Yep, you read the post title correctly – SharePoint 2007, Microsoft Office SharePoint Server.  Good ol’ MOSS.

I’ve been working on a project recently where MOSS is in place.  Lot’s of MOSS.  In total over 30 farms, something like 300,000 users dependent on who you ask.  A ton of MOSS.

I like MOSS.  It was a simpler thing from a simpler time.  Sure, it has problems but doesn’t everything?

Anyway, enough of the philosophising.

A number of the farms in the estate were exhibiting issues with broken webs.  These broken webs would cause all kinds of oddities.  Timer jobs would croak, user experience would be impacted, Search was having kittens.  You get the problem.

With tens of thousands of webs in some of the farms, locating the broken ones was proving challenging and was being managed through case-by-case analysis of inbound helpdesk calls.  Not ideal.

Unsurprisingly, PowerShell, even with MOSS, would be a good way to uncover all of the webs that were exhibiting problems so they could then be analysed protectively – a better approach all round.

All up, it’s not too complex, load the assembly, instantiate a farm object and walk through it.  The key is in the scripts ability to ignore web applications that don’t contain content as they’re SSP web applications or the Central Admin web app.  It keeps the output clean and uncluttered, just the way I like it.

See the comments for more information about what’s going on and as always, use with caution and test, test, test! 🙂

 function Get-SPBrokenSites() { $farm = [Microsoft.SharePoint.Administration.SPFarm]::Local # define the counters we will use in the loops $badresult = @() # use a continue loop to check for web applications foreach ($spService in $farm.Services) { if (!($spService.typename -match "Windows SharePoint Services Web Application")) { continue } # loop through the sp services we know to be web applications foreach ($webApp in $spService.WebApplications) { # test the web app to ensure it is not the central admin web app, we dont care about this one if ($webApp -is [Microsoft.SharePoint.Administration.SPAdministrationWebApplication]) { continue } if (($webApp.Properties.Keys) -match "SharedResourceProvider") { Write-Host "INFO: $($ is an SSP, skipping" -BackgroundColor Yellow Write-Host } else { Write-Host "INFO: $($ is not an SSP, analysing sites..." -BackgroundColor Yellow # loop through all of the site collections in the web apps foreach ($site in $webApp.Sites) { # loop through all of the webs in the site collections foreach ($web in $site.AllWebs) { Write-Host try { Write-Host "$($web.url) is: " -NoNewline foreach ($list in $web.Lists) { # this for...each is to exercise the web to generate an error if it's broken # we could use other types of exercise to test for more specific error conditions if desired # go wild and use your imagination! } Write-Host "OK!" -BackgroundColor DarkGreen } catch { Write-Host "GOOBERED!" -BackgroundColor Red -ForegroundColor White $badresult += New-Object PSObject -Property @{ WebName = $web.title URL = $web.url Status = 'Goobered' } } $web.Dispose() } $site.Dispose() } } } } $badresult | Export-Csv c:\Users\Administrator.BIGSEB\Desktop\badresult.csv -NoTypeInformation } # do the work here $ErrorActionPreference="Stop" ; $Error.Clear() [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") Clear-Host Get-SPBrokenSites 

more to follow…