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 comment

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