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 23, 2022Copper Contributor
Thanks 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, 2022
dklbwf try this 🙂
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Variables
$ListName = "vr"
$List = (Get-SPWeb $SiteURL).Lists.TryGetList($ListName)
$ItemIDs = 17148, 17147
foreach($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
- Oct 24, 2022Ah sorry mate! It should be $List.GetItemById($ItemID) not $List.GetItemByUniqueId($ItemID)
- dklbwfOct 24, 2022Copper Contributor
NicolasKheirallah Thanks for the quick response! After updating it is saying it can't find item even though the ID im using is there. I've tried several different ID's but same error. Thanks again