Saturday, September 8, 2012

Deleting All Items with PowerShell

This is a very simple script that deletes all items and display the amount of items left;


$list = (Get-SPWeb <web url>).Lists[<list name>]
for ($i=$list.ItemCount-1; $i -ge 0; $i--) { $list.Items[$i].Delete(); $i; }

The documents deletion can also look like (Notice the file): 

$list = (Get-SPWeb <web url>).Lists[<list name>]
for ($i=$list.ItemCount-1; $i -ge 0; $i--) { $list.Items[$i].File.Delete(); $i; }

No comments:

Post a Comment