One of those “it may come in useful one day” scripts. It walks through a site hierarchy in SharePoint 2010, reports the size of each one, and then displays a total size for all sites reported. It uses the concepts of the code specified in this article, which calculates the size of a site by adding up the contents of each folder within it.
To use, first run the following script:
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
}
Once you have run the script, you can call it with the following PowerShell command:
GetWebSizes -StartWeb <StartURL>
Using a start URL allows you to perform a size check from any site in the hierarchy – not just the top level site. In the example below, I ran it against the URL http://portal, but could also choose to run it from a sub-site, if required:
PS C:\> GetWebSizes -StartWeb http://portal
Site Intranet is 12763801 KB
Site Hello is 581759 Bytes
Site Team Site is 604175 Bytes
Total size of all sites below http://portal is 13949735 Bytes,
which is 13.30 MB or 0.01 GB
Fuente: http://get-spscripts.com/2010/08/check-size-of-sharepoint-2010-sites.html
Comentarios