Home > PowerShell, SharePoint 2010, SharePoint Administration > Get The Total Number of Versions For All Items in a Site Collection using PowerShell

Get The Total Number of Versions For All Items in a Site Collection using PowerShell

Recently I was tasked to get the total number of versions for all items in a Site Collection with 10 or more versions.  This script took me a little while to do because I could not find any good references on how I could accomplish this, well via Google that is.  But eventually I found out a way to accomplish this, and also have it generate an .htm document with the results for cleaner results.

Below is the script I used to accomplish this.

_____________________________________________________________________________________________

$site = Get-SPSite http://portalsite/site
$webs = $site.AllWebs
$itemVersionCount = 0
$itemAllCount = 0

foreach($web in $webs)
{
write-host “———————————————————————————————————————-“
write-host “Site URL: ” -ForegroundColor Yellow $Web.URL
$WebURL = $Web.URL
write-output “<b><font color=”Green”><u>Site URL:</u></b> <a href=”$WebURL”>$WebURL</a></font><br>” >> c:\temp\versions.htm
write-output “<br>” >> c:\temp\versions.htm

foreach($list in $web.Lists)
{
if($list.EnableVersoning -and $list.Items.Count -gt 0 -and ($list.Title -notlike ‘Images’ -and $list.Title -notlike ‘Pages’ -and $list.Title -notlike ‘Site Pages’ -and $list.Title -notlike ‘Master Page Gallery’ -and $list.Title -notlike ‘Page Content’ -and $list.Title -notlike ‘Style Library’))
{
write-host “Document Library: ” -ForegroundColor Cyan $list.Title
$listTitle = $list.Title
write-output “<b><font color=”blue”><u>Document Library:</u></b></font> $listTitle<br>” >> c:\temp\versions.htm
write-host “Files: ” -ForegroundColor Red
write-output “<b><font color=”red”><u>Files:</u></b></font><br>” >> c:\temp\versions.htm

foreach($item in $list.Items)
{
if ($list.Versions.Count -ge 10)
{
$itemVersionCount += 1
write-host $item.Name “| Versions: ” $item.Versions.Count
$itemName = item.Name
$versionCount = $item.Versions.Count
write-output “$itemName | Versions: $versionCount <br>” >> c:\temp\versions.htm
}
if($list.Versions.Count -lt 10)
{
$itemAllCount += 1
}

write-host “Total # of Files in List/Library: ” -ForegroundColor Green $list.Items.Count
$listCount = $list.Item.Count
write-output “<b><font color=”blue”><u>Total # of Files in List/Library:</u></b></font> $listCount <br>” >> c:\temp\versions.htm

$sum = $itemVersionCount + $itemAllCount
write-host “Total # of files with 10 or more Versions: ” $itemVersionCount
write-output “<b><font color=”blue”><u>Total # of files with 10 or more Versions:</b></u></font> $itemVersionCount <br>” >> c:\temp\versions.htm

if ($itemAllCount -eq $sum)
{
write-host “No Files with 10 or more Versions”
write-output “<font color=”red”>No Files with 10 or more Versions</font><br>” >> c:\temp\versions.htm
}

$itemVersionCount = 0
$itemAllCount = 0
write-host ” “
write-output “<br>” >> c:\temp\versions.htm
}
}
}
$site.Dispose()

_____________________________________________________________________________________________

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: