Question

I need to inventory a web app. I have this script below that works like a charm except that I'd really like the size of each Web. Is it possible to do this using this script?

Get-SpWebApplication <insert web app URL here> | 
  Get-SPSite -Limit All | 
     Get-SPWeb -Limit All | 
       Select Title, URL, ID, ParentWebID | 
         Export-CSV “<insert csv file path and name here>” -NoTypeInformation

Script from sebmatthews

Was it helpful?

Solution

Size is not directly available. You should iterate through the SPWeb folders and then add up the file size.

$webs = Get-SpWebApplication <insert web app URL here> | 
  Get-SPSite -Limit All | 
     Get-SPWeb -Limit All

$results = @()
foreach($web in $webs)
{
    $size = GetWebSize($web)

    $result = New-Object System.Object
    $result | Add-Member -type NoteProperty -name Title -value $web.Title
    $result | Add-Member -type NoteProperty -name URL -value $web.URL
    $result | Add-Member -type NoteProperty -name ID -value $web.ID
    $result | Add-Member -type NoteProperty -name ParentWebID  -value $web.ParentWebID 
    $result | Add-Member -type NoteProperty -name Size  -value $size

    $results += $result
}

$results | export-csv "<insert csv file path and name here>" -NoTypeInformation

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
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top