Howto: Check all the sites in the particular Content DB

From time to time, there is a need to check the SharePoint sites is a particular content database are accessible. There is a simple script for it:  enumerate all the sites in the DB and Invoke a Web Request for the site URL. The returned Web request code will indicate if site is accessible or not:

####################################################################################################
#
# Author.......: David Shvartsman
# Date.........: 07/05/2018
# Description..: Check all the sites in the particular Content DB
#
####################################################################################################
#Load SharePoint PowerShell Snapin
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
$db = "Content_DBName"
$Sites = Get-SPSite -ContentDatabase $db -Limit All
foreach ($site in $sites) {
    $SiteStatus = Invoke-WebRequest -Uri $site.url -UseDefaultCredentials | Select-Object StatusCode

    If ($siteStatus.StatusCode -eq 200) {
        Write-host "$($site.url) is OK." -ForegroundColor Green
    }
    Else {
        Write-Host "Failed check for $($site.url)" -ForegroundColor Red
    }
}

####################################################################################################

That was another page in the Chronicles of SharePoint Bits, happy scripting!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.