0

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

  • Hi @ExceptionLimeCat some time ago, I had to do the same that you have to do now and I found a script in a blog, I dont remember the blog :(, but i save the script :D I hope this work for you Get Web Size – Marco Jan 15 '15 at 19:31
0

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
}
  • I was hoping that looping through the files wouldn't be necessary. Thanks for your help. – ExceptionLimeCat Jan 15 '15 at 20:32
  • @ExceptionLimeCat you can pipe it, but I am not that expert in scripting :) – Amal Hashim Jan 15 '15 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.