Thursday, 25 July 2013

Using Write-Progress in a Long Running SharePoint PowerShell Script

I wrote an article on the Microsoft TechNet Wiki about using the PowerShell Write-Progress cmdlet within a long running PowerShell script. The wiki article can be seen here: An Example of Using Write-Progress in a Long Running SharePoint PowerShell Script

I thought I'd summarise the article here too.

I uploaded the script that I based my example on to the TechNet Gallery, and it can be downloaded from here: List or Delete excess ListItem Versions in a SharePoint List or Document Library

This article covers a simple scenario of using Write-Progress with a long running script that performs iterations of all the item versions in a SharePoint list, within a web and all of its sub-webs. It highlights how to nest progress bars and dynamically set the percent (%) complete. It also demonstrates using informative progress status messages.

Here are a few screen shots from the article, that demonstrate the use of the Write-Progress in a script.

Example: Enumerate all of the publishing pages in the Pages library (if found) of the sneakpreview web, and all sub-webs of sneakpreview. Store all versions of a page in excess of 5 versions in the $excessVersions variable.
$excessVersions = Get-ExcessListItemVersions -SiteUrl "http://sneakpreview  " -ListTitle "Pages" -MaxVersions 5 -Recurse



Example: Enumerate all of the publishing pages in the Pages library (if found) of the sneakpreview/informationtechnology/teamsite web.
$excessVersions = Get-ExcessListItemVersions -SiteUrl "http://sneakpreview/informationtechnology/teamsite  " -ListTitle "Pages" -MaxVersions 5