Forum Discussion
dklbwf
Oct 21, 2022Copper Contributor
Powershell script to update multiple items from ID field
Hello, I have a request for 2 SharePoint 2013 OnPrem list where they are needing 1,000 records in both lists to simply have the status updated to completed and comment added for specific records. O...
- Oct 23, 2022dklbwf try this 🙂Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue#Variables$ListName = "vr"$List = (Get-SPWeb $SiteURL).Lists.TryGetList($ListName)$ItemIDs = 17148, 17147foreach($ItemID in $ItemIDs){$SPListItem = $List.GetItemByUniqueId($ItemID)$ListItem["Status"]="Completed"$ListItem["Request Comment"]="Completed 10-21-2022"$SPListItem.Update()}
dklbwf
Oct 22, 2022Copper Contributor
Thanks for response. This is actually older SharePoint 2013 OnPrem envrionment.
Oct 23, 2022
Is it all items in those SharePoint list?
in case you can use this:
$web = Get-SPWeb https://yoursite #Get the List $List = $web.Lists["YourList"] #Get All Items in the list $ListItems = $List.items #Iterate through each item foreach($Item in $ListItems) { #Update the value of your "YourField" $item["YourField"] = "Hello!" #Update the item $item.Update() }
- dklbwfOct 23, 2022Copper ContributorThanks for response. It's not all items, I am needing to update only specific items and wanting to update them by using the ID assigned to each item in the list.
- Oct 23, 2022dklbwf try this 🙂Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue#Variables$ListName = "vr"$List = (Get-SPWeb $SiteURL).Lists.TryGetList($ListName)$ItemIDs = 17148, 17147foreach($ItemID in $ItemIDs){$SPListItem = $List.GetItemByUniqueId($ItemID)$ListItem["Status"]="Completed"$ListItem["Request Comment"]="Completed 10-21-2022"$SPListItem.Update()}
- dklbwfOct 24, 2022Copper Contributor
NicolasKheirallah This is the error I am seeing when I run the script