SharePoint portal in active company grows like an anthill. Setting limits of SharePoint sites can protect from problems with disk spaces, but it makes more users requests that not all the administrators like. So I think a good tone not to set limits on SharePoint sites.

But in this case we need monitoring of sites to see how much space they take.

For this I posted a useful powershell script to see disc usage by SharePoint sites. Here it is.

 

<# Script for calculating SharePoint SPWeb size #>
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
{
    Write-Host "Pluging Sharepoint modules"
    Add-PSSnapin Microsoft.SharePoint.PowerShell
}


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
    }

GetWebSizes -StartWeb http://yourspportal/site/