SharePoint Site Storage Management Information

Some days ago I got a job to collect and create report from a subsites size of site collection. I found several article which says the information can be collected from folder and subfolder files and their versioning size. However I wrote the script it did not convinced me about the result, because there is differential of the site collection size.  After some of searching I found a solution on the codeplex.com (SPUsedSpaceInfo) which gave me the best direction and I found the best method (spsite.storagemanagementinformation) in the source code for my script in PowerShell .

How it works?

param (
        [string]$Url = "",
        [boolean]$Export = $false
      )
      
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$Site = New-Object Microsoft.SharePoint.SPSite($Url)

$ListStorageInformation = $Site.StorageManagementInformation("List","Increasing","Size",0)
$DocumentLibraryStorageInformation = $Site.StorageManagementInformation("DocumentLibrary","Increasing","Size",0)
$DocumentStorageInformation = $Site.StorageManagementInformation("Document","Increasing","Size",0)
    
"Total size of List: {0:N2} MB" -f (($ListStorageInformation | Measure-Object -Property Size -Sum).Sum/1MB)
"Total size of DocumentLibrary: {0:N2} MB" -f (($DocumentLibraryStorageInformation | Measure-Object -Property Size -Sum).Sum/1MB)
"Total size of Document: {0:N2} MB" -f (($DocumentStorageInformation | Measure-Object -Property Size -Sum).Sum/1MB)

If ($Export -eq $true)
    {
        $Path = (Get-Location).Path + "\" + "{0:ddMMyyHHmm}_" -f (Get-Date) + ($site.RootWeb -Replace " ","_") + "_List.csv"
        "Exporting all List Storage Information here: $Path"
        $ListStorageInformation | Select Directory, Title, Size, Count | Export-Csv -Path $Path -Delimiter ";"
            
        $Path = (Get-Location).Path + "\" + "{0:ddMMyyHHmm}_" -f (Get-Date) + ($site.RootWeb -Replace " ","_") + "_DocumentLibrary.csv"
        "Exporting all DocumentLibrary Storage Information here: $Path"
        $DocumentLibraryStorageInformation | Select Directory, Title, Size, Count | Export-Csv -Path $Path -Delimiter ";"
        
        $Path = (Get-Location).Path + "\" + "{0:ddMMyyHHmm}_" -f (Get-Date) + ($site.RootWeb -Replace " ","_") + "_Document.csv"
        "Exporting all DocumentLibrary Storage Information here: $Path"
        $DocumentStorageInformation | Select Directory, LeafName, TotalSize | Export-Csv -Path $Path -Delimiter ";"        
        
    }

Collect total storage information per List, Document Library and Document:

.\Get-SPSiteStorageInformation -Url 

Collect storage information and export it into a simple report file in .csv format:

.\Get-SPSiteStorageInformation -Url  -Export $true

Monitoring if there are any opened content databases

Here is a little script which monitoring content databases. First we have to create a new event source on the SharePoint server.

New-EventLog -LogName Application -Source "My-SharePoint-Event"

Checking if the “CurrentSiteCount” is less than “WarningSiteCount” and create an event log entry in the Application log. You can set your monitoring system to open ticket by this event if necessary.

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
$databases = $farm | 
    select -ExpandProperty services | 
        ?{$_ -is [Microsoft.SharePoint.Administration.SPDatabaseService]} |
            select -expand instances | select -expand databases | 
                ?{$_.currentsitecount -lt $_.warningsitecount} |
                    select name
if ($databases -eq $null)   
                {Write-EventLog -LogName Application -Source "My-SharePoint-Event" -EventID 3333 -EntryType Error -Message "All social content databases are getting full."}
                else
                {Write-EventLog -LogName Application -Source "My-SharePoint-Event" -EventID 3334 -EntryType Information -Message ("Available social content databases " + $databases.name)}

You can add multiple condition if you want to checking special content databases e.g. if the content database name contains “WSS_Content*”:

?{($_.name -like "WSS_Content*") -and ($_.currentsitecount -lt $_.warningsitecount)}

I am back…

Hi,

Unfortunately, my previous provider gone, I mean servers are shut down and my previous posts lost. Probably some of them will be recovered, but not all.

There is a second chance for me to a fresh start! 🙂