Forum Discussion
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. Of course, this would take a lot of hours to manually touch 2,000 records. I've tried to put together a script that will use ID field and then update the status and comment field but no luck with the test. Can someone possibly tell me what I might be missing? Am I using incorrect field names in the script for the default ID? Thanks a ton for any help.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Variables
$SiteURL = "http://siteaddress/"
$ListName = "vr"
#Get the List
$List = (Get-SPWeb $SiteURL).Lists.TryGetList($ListName)
#List of Item IDs to update
$ItemIDs = 17148, 17147
If($list)
{
foreach($ItemID in $ItemIDs)
{
#Get Item by ID
$ListItem = $List.GetItembyID($ItemID)
#Update List Item Fields
$ListItem["Status"]="Completed"
$ListItem["Request Comment"]="Completed 10-21-2022"
$ListItem.SystemUpdate()
Write-host "Updated Item ID:"$ItemID
}
}
- dklbwf 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()}
- RobElliottSilver Contributor
dklbwf you could do this with a simple flow in Power Automate. With 1000 records in each list it woul take a short while to run but is probably a more simple solution.
Rob
Los Gallardos
Microsoft Power Automate Community Super User- dklbwfCopper ContributorThanks for response. This is actually older SharePoint 2013 OnPrem envrionment.
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() }