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

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

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

_____________________________________________________________________________________________

Advertisements
  1. Venkat Vaddi
    October 15, 2013 at 2:51 pm

    Nice Post. (PS: Script missing a closing paranthesis ‘}’ )

  2. October 15, 2013 at 2:51 pm

    Nice Post. (Script is missing a closing paranthesis “}” )

  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: