Update a Column Value for All List Items in SharePoint using PowerShell
Requirement is to update a list item in SharePoint using PowerShell. Here are some code scripts to update SharePoint list item using PowerShell script.
PowerShell to update a column value for all List items in SharePoint
The syntax for updating a specific column value on SharePoint List item goes like this:
SharePoint PowerShell update list item by id:
Lets pick a specific list item from its ID and update it.
Update list item SharePoint 2010 using PowerShell
This script picks a list item using its field value and updates it using PowerShell.
PowerShell to update a column value for all List items in SharePoint
The syntax for updating a specific column value on SharePoint List item goes like this:
$Web = Get-SPWeb "http://sharepoint-site-url" $List = $web.Lists["List Name"] foreach ($item in $list.Items) { $item["ColumnName"] = "New value" $item.Update() }This PowerShell updates all list items in SharePoint. Here is an example for update all items in a SharePoint list with PowerShell:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue #Get the List $Web = Get-SPWeb "http://intranet.crescent.com" $List = $web.Lists["Contacts"] #Get all List Items $ListItems = $List.Items #if the Item Found foreach($Item in $ListItems) { #Update 'Company' Field Value $Item["Company"] = "Crescent Inc." $Item.Update() }
SharePoint PowerShell update list item by id:
Lets pick a specific list item from its ID and update it.
#Get the List $Web = Get-SPWeb "http://intranet.crescent.com" $List = $web.Lists["Contacts"] #Get the List Item from Its ID $ListItem = $List.GetItemById("1") #Update 'Last Name' Column $ListItem["Last Name"] = "Thomas Cook" $ListItem.Update()
Update list item SharePoint 2010 using PowerShell
This script picks a list item using its field value and updates it using PowerShell.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue #Get the List $Web = Get-SPWeb "http://intranet.crescent.com" $List = $web.Lists["Contacts"] #Get the List Item from column value $ListItem = $List.Items | Where { $_["Last Name"] -eq "Thomas" } #if the Item Found if($ListItem) { #Update 'Last Name' Column $ListItem["Last Name"] = "Thomas Cook" $ListItem.Update() }
No comments:
Please Login and comment to get your questions answered!