72 lines
1.8 KiB
PowerShell
72 lines
1.8 KiB
PowerShell
param(
|
|
[string]$url
|
|
)
|
|
|
|
if (-not $url)
|
|
{
|
|
Write-Host "Specify site url in url parameter" -foregroundcolor red
|
|
return
|
|
}
|
|
|
|
function GetWebSizes ($web)
|
|
{
|
|
#$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"
|
|
Write-Host $web.Url": "$totalInMb
|
|
$str = $web.Url + ";" + $totalInMb.ToString().Replace(".", ",")
|
|
$str | Out-File "site-size-detailed.csv" -Append
|
|
}
|
|
|
|
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)
|
|
{
|
|
$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)
|
|
{
|
|
$folderSize = 0
|
|
foreach ($file in $folder.Files)
|
|
{
|
|
$folderSize += $file.Length;
|
|
}
|
|
foreach ($fd in $folder.SubFolders)
|
|
{
|
|
$folderSize += GetFolderSize -Folder $fd
|
|
}
|
|
return $folderSize
|
|
}
|
|
|
|
$site = Get-SPSite $url
|
|
$site.RootWeb.Webs | ForEach-Object { GetWebSizes $_ } |