Sharepoint Update List Item Power Shell

Scenario: You added a new column and need to update that column for every item in a list or library. Solution: Here is an example PowerShell script that can be used to update one or more columns for every single item in a list.

-->

Syntax

Examples

------------------EXAMPLE 1------------------

Sets fields value in the list item with ID 1 in the 'Demo List'. It sets both the Title and Category fields with the specified values. Notice, use the internal names of fields.

------------------EXAMPLE 2------------------

Sets fields value in the list item with ID 1 in the 'Demo List'. It sets the content type of the item to 'Company' and it sets both the Title and Category fields with the specified values. Notice, use the internal names of fields.

------------------EXAMPLE 3------------------

Sets fields value in the list item which has been retrieved by for instance Get-PnPListItem. It sets the content type of the item to 'Company' and it sets both the Title and Category fields with the specified values. Notice, use the internal names of fields.

------------------EXAMPLE 4------------------

Sets the retention label in the list item with ID 1 in the 'Demo List'.

Parameters

-Connection

Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection.

Type:SPOnlineConnection
Position:Named
Accept pipeline input:False
Accept wildcard characters:False

Specify either the name, ID or an actual content type

Type:ContentTypePipeBind
Position:Named
Accept pipeline input:False
Accept wildcard characters:False

The ID of the listitem, or actual ListItem object

Type:ListItemPipeBind
Position:Named
Accept pipeline input:True
Accept wildcard characters:False

The name of the retention label.

Only applicable to: SharePoint Online

Type:String
Position:Named
Accept pipeline input:False
Accept wildcard characters:False

The ID, Title or Url of the list.

Type:ListPipeBind
Position:0
Accept pipeline input:True
Accept wildcard characters:False

Update the item without creating a new version.

Only applicable to: SharePoint Online

Type:SwitchParameter
Position:Named
Accept pipeline input:False
Accept wildcard characters:False

Use the internal names of the fields when specifying field names.

Single line of text: -Values @{'TextField' = 'Title New'}

Multiple lines of text: -Values @{'MultiTextField' = 'New textnnMore text'}

Rich text: -Values @{'MultiTextField' = '<strong>New</strong> text'}

Choice: -Values @{'ChoiceField' = 'Value 1'}

Number: -Values @{'NumberField' = '10'}

Currency: -Values @{'NumberField' = '10'}

Currency: -Values @{'CurrencyField' = '10'}

Date and Time: -Values @{'DateAndTimeField' = '03/13/2015 14:16'}

Lookup (id of lookup value): -Values @{'LookupField' = '2'}

Multi value lookup (id of lookup values as array 1): -Values @{'MultiLookupField' = '1','2'}

Multi value lookup (id of lookup values as array 2): -Values @{'MultiLookupField' = 1,2}

Multi value lookup (id of lookup values as string): -Values @{'MultiLookupField' = '1,2'}

Yes/No: -Values @{'YesNoField' = $false}

Person/Group (id of user/group in Site User Info List or email of the user, separate multiple values with a comma): -Values @{'PersonField' = 'user1@domain.com','21'}

Managed Metadata (single value with path to term): -Values @{'MetadataField' = 'CORPORATE DEPARTMENTS FINANCE'}

Managed Metadata (single value with id of term): -Values @{'MetadataField' = 'fe40a95b-2144-4fa2-b82a-0b3d0299d818'} with Id of term

Managed Metadata (multiple values with paths to terms): -Values @{'MetadataField' = ('CORPORATE DEPARTMENTS FINANCE','CORPORATE DEPARTMENTS HR')}

Managed Metadata (multiple values with ids of terms): -Values @{'MetadataField' = ('fe40a95b-2144-4fa2-b82a-0b3d0299d818','52d88107-c2a8-4bf0-adfa-04bc2305b593')}

Hyperlink or Picture: -Values @{'HyperlinkField' = 'https://github.com/OfficeDev/, OfficePnp'}

Type:Hashtable
Position:Named
Accept pipeline input:False
Accept wildcard characters:False

This parameter allows you to optionally apply the cmdlet action to a subweb within the current web. In most situations this parameter is not required and you can connect to the subweb using Connect-PnPOnline instead. Specify the GUID, server relative url (i.e. /sites/team1) or web instance of the web to apply the command to. Omit this parameter to use the current web.

Type:WebPipeBind
Position:Named
Accept pipeline input:False
Accept wildcard characters:False

Outputs

Microsoft.SharePoint.Client.ListItem

Related Links

-->

Applies to: SharePoint Foundation 2010

Creating, updating, or deleting list items through the client object model works similarly to performing these tasks through the server object model. You create a list item object, set its properties, and then update the object. To modify or delete a list item object, use the GetById() method of the ListItemCollection class to return the object, and then either set properties and call update on the object that this method returns, or call the object's own method for deletion. Unlike the server object model, each of these operations in the client object model must conclude with a call to ExecuteQuery() or ExecuteQueryAsync(ClientRequestSucceededEventHandler, ClientRequestFailedEventHandler) (JavaScript: executeQueryAsync(succeededCallback, failedCallback)) for changes to take effect on the server.

Creating a list item

To create list items, you create a ListItemCreationInformation object, set its properties, and pass it as parameter to the AddItem(ListItemCreationInformation) method of the List class. Set properties on the list item object that this method returns, and then call the Update() method, as seen in the following example.

Because the previous example creates a standard list item, you do not need to set properties on the ListItemCreationInformation object before it is passed to the AddItem(ListItemCreationInformation) method. However, if your code must create a new folder, for example, you must set the UnderlyingObjectType of the ListItemCreationInformation to Folder.

For information and an example about how to create a list item object within the context of the Microsoft SharePoint Foundation 2010 Silverlight object model, see Using the Silverlight Object Model.

Updating a list item

To set most list item properties, you can use a column indexer to make an assignment, and call the Update() method so that changes will take effect when you call ExecuteQuery() or ExecuteQueryAsync(ClientRequestSucceededEventHandler, ClientRequestFailedEventHandler). The following example sets the title of the third item in the Announcements list.

Deleting a list item

To delete a list item, call the DeleteObject() method on the object. The following example uses the GetItemById() method to return the second item from the list, and then deletes the item.

SharePoint Foundation 2010 maintains the integer IDs of items within collections, even if they have been deleted. So, for example, the second item in a list might not have 2 as its identifier. A ServerException is returned if the DeleteObject() method is called for an item that does not exist.

If you want to retrieve, for example, the new item count that results from a delete operation, include a call to the Update() method to refresh the list. In addition, you must load either the list object itself or the ItemCount property on the list object before executing the query. If you want to retrieve both a start and end count of the list items, you must execute two queries and return the item count twice, as shown in the following modification of the previous example.

Sandinista clash rar

Update

See Also

Concepts

Other Resources