Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update all items in a list using PowerShell

I have a SharePoint 2010 list with around 500 items. I need to create a PowerShell script that will call ALL of these list items, and then update a specific column (we'll call it 'Number') for EACH item.

The column (Number) that needs to be updated for each item is a Number column. I simply need to insert a random number into each list item, ranging from 0-100. It doesn't matter if numbers are repeated, but they need to be chosen at random.

I am very new to PowerShell and am still trying to understand the fundamentals. If someone could provide me with assistance around how to configure this cmdlet, that would be greatly appreciated!

Thanks so much!

-Josh

like image 728
Josh Henninger Avatar asked Mar 30 '12 16:03

Josh Henninger


People also ask

How do I mass update a SharePoint list?

Edit more than one item at a time Select two or more items or files in a ​​​​​​list or library. Select the information icon on the command bar to open the details pane. Enter one or more new values in the Bulk edit properties area. Save to apply the new values to all the selected items.

What is the fastest way to update a SharePoint list?

To update the SharePoint list from Excel, you have to click on the "Edit" hyperlink on any row/item to modify. This hyperlink open the "edit item" page on SharePoint. Modify the item and Save it. Go back to Excel and refresh the table.


2 Answers

Assuming the list you want to update is located at http://YouServer/ListLocation/Lists/TheList:

$web = Get-SPWeb http://YourServer/ListLocation
$list = $web.Lists["TheList"]

foreach ($item in $list.Items)
{
  $item["Number"] = Get-Random -Min 0 -Max 100;
  $item.Update();
}

You need to execute this code in the SharePoint 2010 Management Shell or add the SharePoint PowerShell snap-in manually:

Add-PSSnapin Microsoft.SharePoint.PowerShell
like image 127
Stefan Avatar answered Sep 26 '22 18:09

Stefan


You may try something like the following:

$list | ForEach-Object { $_.Number = Get-Random -Min 0 -Max 100 }
like image 39
Joey Avatar answered Sep 25 '22 18:09

Joey