Wednesday, April 17, 2013

View size of all document libraries using PowerShell

Quick and dirty post this time around.  This PowerShell script will analyse all document libraries in a site collection and dump the results in a (very basic) comma-seperated text file called output.txt.  The size will be in KB.


$sitecol = Get-SPSite -Identity http://sharepoint

foreach($site in $sitecol)
{
  foreach($s in $site.AllWebs)
  {
    foreach($l in $s.lists)
    {
      if($l.BaseType -eq "DocumentLibrary") {
        $listSize = 0
        foreach($item in $l.items) {
          $listSize += ($item.file).length
        }
        $filesize = [string][Math]::Round(($listSize/1KB),2)
        $title = $filesize + "," + $s.Title + ":" + $l.Title
        $title >> "output.txt"
      }
    }
    $s.Dispose()
  }
}

No comments:

Post a Comment