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.

$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."}
                {Write-EventLog -LogName Application -Source "My-SharePoint-Event" -EventID 3334 -EntryType Information -Message ("Available social content databases " + $}

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

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

I am back…


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! 🙂