Archive

Archive for May, 2012

Get all Installed Features in SharePoint 2010 Farm using PowerShell

May 30, 2012 Leave a comment

If you would like to get a list of all the SharePoint features (Default & Custom) installed in your SharePoint 2010 Farm (Farm, WebApp, Site Collection, Site) you can reference this script.

______________________________________________________________________________________________

Get-SPFeature | Sort -Property Scope, DisplayName | Ft -Autosize -GroupBy Scope DisplayName, Id > c:\temp\allinstalledfeatures.txt

______________________________________________________________________________________________

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

May 21, 2012 Leave a comment

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()

_____________________________________________________________________________________________

Getting Size Matrices for Document Library, List Libraries, and Items in a SharePoint 2010 Site Collection Using PowerShell

May 16, 2012 2 comments

I recently had to gather some Site Collection matrices for all my Document Libraries, Lists, and Items sizes of a specific Site Collection to generate a report.

The way I was able to accomplish this is by using the now ‘obsolete’ API StorageManagementInformation function.  http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsite.storagemanagementinformation.aspx

Even though this function is labeled as ‘obsolete’ according to Microsoft, it still works.

A little information about the function it takes 4 parameters:

  1. ltVar: What kind of storage management information to display
    • List = 1
    • DocumentLibrary = 2
    • Document = 3
  2. sordVar: the direction in which the items are to be sorted
    • Increasing = 0×10
    • Decreasing = 0×11
  3. soVar: whether the items are sorted by size or by date
    • Size=0
    • Date = 1
  4. nMaxResults: the number of results to return

With that said use at our own risk, I’m not responsible for your farm.

Below is the PowerShell script I generated to accomplish my task.

____________________________________________________________________________________________

$web = Read-Host “Enter in the Site Collection URL to gather Size Matrices”
$lists = $web.Lists
$DocLibCount = 0  #Counter used to hold the total number of Document Libraries in the Site Collection
$ListLibCount = 0  #Counter used to hold the total number of Lists in the Site Collection

#foreach loop that loops through the Site Collection, checks to see if the list is a document library or a list and generates a count

foreach ($list in $lists)
{
if ($list.BaseType -eq “DocumentLibrary”)
#checks to see if the list item is a Document Library
{
$DocLibCount += 1 #document library counter
}
if ($list.BaseType -eq “GenericList”) #checks to see if the list item is a List
{
$ListLibCount += 1
#list counter
}

$site = Get-SPSite $web
write-output “Document Library” >> c:\temp\sizereport.txt
$site.StorageManagementInformation(2, “Decreasing”, “Size”, $DocLibCount) | ft -wrap -autosize Directory, LeafName, Size >> c:\temp\sizereport.txt  #call the StorageManagementInformation function and pass it the 4 parameters to get the size matrices of the Document Libraries.
write-output “Lists” >> c:\temp\sizereport.txt
$site.StorageManagementInformation(1, “Decreasing”, Size”, $ListLibCount) | ft -wrap -autosize Directory, LeafName, Size >> c:\temp\sizereport.txt #call the StorageManagementInformation function and pass it the 4 parameters to get the size matrices of the Lists.
write-output “Items” >> c:\temp\sizereport.txt
$site.StorageManagementInformation(3, “Decreasing”, Size”, $list.item.count) | ft Directory, LeafName, Size >> c:\temp\sizereport.txt #call the StorageManagementInformation function and pass it the 4 parameters to get the size matrices of the items.

$site.dispose()

_____________________________________________________________________________________________