by

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)}