1

Can someone please help me to export all site collections and subsites storage sizes in an Web Application using PowerShell?

1

Try the below script, output is little messy but you will get your required result.

Run the below scipt

if(!(Get-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction:SilentlyContinue)) 
{ 
   Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction:SilentlyContinue
} 


function GetWebSizes ($StartWeb)
{
    $web = Get-SPWeb $StartWeb
    [long]$total = 0
    $total += GetWebSize -Web $web
    $total += GetSubWebSizes -Web $web
    $totalInMb = ($total/1024)/1024
    $totalInMb = "{0:N2}" -f $totalInMb
    $totalInGb = (($total/1024)/1024)/1024
    $totalInGb = "{0:N2}" -f $totalInGb
    write-host "Total size of all sites below" $StartWeb "is" $total "Bytes,"
    write-host "which is" $totalInMb "MB or" $totalInGb "GB"
    $web.Dispose()
}

function GetWebSize ($Web)
{
    [long]$subtotal = 0
    foreach ($folder in $Web.Folders)
    {
        $subtotal += GetFolderSize -Folder $folder
    }
    write-host "Site" $Web.Title "is" $subtotal "KB"
    return $subtotal
}

function GetSubWebSizes ($Web)
{
    [long]$subtotal = 0
    foreach ($subweb in $Web.GetSubwebsForCurrentUser())
    {
        [long]$webtotal = 0
        foreach ($folder in $subweb.Folders)
        {
            $webtotal += GetFolderSize -Folder $folder
        }
        write-host "Site" $subweb.Title "is" $webtotal "Bytes"
        $subtotal += $webtotal
        $subtotal += GetSubWebSizes -Web $subweb
    }
    return $subtotal
}

function GetFolderSize ($Folder)
{
    [long]$folderSize = 0  
    foreach ($file in $Folder.Files)
    {
        $folderSize += $file.Length;
    }
    foreach ($fd in $Folder.SubFolders)
    {
        $folderSize += GetFolderSize -Folder $fd
    }
    return $folderSize
}

In the same window now run the below command:

$web = Get-SPWebApplication "Web Application Url"

foreach ($w in $web.Sites)
{
    GetWebSizes -StartWeb $W.Url
}

Above script is from this Check the size of SharePoint 2010 sites using PowerShell I just tweak it to make sure it run against a web application.

  • Thank you Sarwar .Its working but can you pls help me to export as a csv file with site url ,site name ,size , total quota – Pradeep Reddy Jan 18 '18 at 16:33
  • Can someone pls help me to export as acsv file with site url ,site name ,size used, total Size , Thank you in advance – Pradeep Reddy Jan 19 '18 at 11:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.