Refresh All Items In The List Using PowerShell

I have a SharePoint 2010 list containing about 500 items. I need to create a PowerShell script that will call ALL of these list items, and then update a specific column (we will call it “Number”) for EVERY element.

The column (Number) that needs to be updated for each item is the Number column. I just need to insert a random number into each list item, starting from 0-100. It does not matter if the numbers are repeated, but they must be chosen arbitrarily.

I am very new to PowerShell and still trying to understand the basics. If someone can provide me with help on how to configure this cmdlet, it will be very helpful!

Many thanks!

-Josh

+5
source share
2 answers

Assuming the list you want to update is 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 run this code in the SharePoint 2010 Management Shell or add the SharePoint PowerShell snap-in manually:

Add-PSSnapin Microsoft.SharePoint.PowerShell
+13
source

You can try something like the following:

$list | ForEach-Object { $_.Number = Get-Random -Min 0 -Max 100 }
+4
source

All Articles