Created
August 23, 2017 09:22
-
-
Save cloudchristoph/c378acc39dd0bc4f82ef73a0708f71e4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment