Update List - PowerShell


Overview

The Update-List command updates the contents of a given list in a SharePoint site. It allows you to add, remove, or modify items in a list, providing a convenient way to manage list data.

Syntax

Update-List [-List] <string> [-Title] <string> [-Description] <string> [-Fields] <string[]> [-ContentType] <string> [-ContentTypeId] <string> [-DefaultView] <string> [-Hidden] [-DisableAttachments] [-AllowContentTypes] <Boolean> [-Item] <ListItem[]> [-Force] [-WhatIf] [-Confirm]

Options/Flags

  • -List: Specifies the name of the list to update.
  • -Title: Sets the title of the list.
  • -Description: Sets the description of the list.
  • -Fields: An array of field objects to add or update in the list.
  • -ContentType: Sets the default content type for the list.
  • -ContentTypeId: Sets the content type ID for the list.
  • -DefaultView: Sets the default view for the list.
  • -Hidden: Hides the list from the site navigation.
  • -DisableAttachments: Disables file attachments in the list.
  • -AllowContentTypes: Allows multiple content types in the list.
    • Default: False
  • -Item: An array of list items to add, update, or remove from the list.
  • -Force: Forces the update to occur, even if the list is locked or contains items with attachments.
  • -WhatIf: Simulates the update without making any changes.
  • -Confirm: Prompts for confirmation before updating the list.

Examples

Simple update:

Update-List -List "My List" -Title "Updated List" -Description "This is an updated list."

Add a new field:

$newField = New-Object Microsoft.SharePoint.Client.Field
$newField.Title = "CustomField"
$newField.FieldType = "Text"
Update-List -List "My List" -Fields @{Add=$newField}

Update an existing item:

$listItem = Get-ListItem -List "My List" -Identity "1"
$listItem["Title"] = "Updated Item Title"
Update-List -Item $listItem -Force

Common Issues:

  • Permission denied: Ensure you have sufficient permissions to update the list.
  • Invalid field: Make sure the field you are adding or updating is a valid field type and doesn’t already exist in the list.
  • List locked: If the list is locked, use the -Force switch to override the lock.

Integration

Update-List can be combined with other commands to automate complex tasks:

Get-List -Web https://contoso.sharepoint.com/sites/site | Update-List -Title "New List" -ContentType "Document" -AllowContentTypes
  • Get-List
  • New-List
  • Remove-List
  • Get-ListItem
  • Add-ListItem
  • Remove-ListItem