I needed an easy way to automatically document my farm and take snap shots of its configuration periodically for audit purposes.

A quick search landed me on this Codeplex project by Jayvijw

As you can see from the above screenshot, the report is quite detailed and contains most of the information you would need as an administrator to track configuration changes and restore a farm to its original configuration if you ever have to start from scratch.

So I thought, why not use PowerShell and Windows Task Scheduler to give me weekly snapshots of my farm’s configuration?


Summary of what the script does

  1. Generate the farm configuration report using the 2010SPSFR.exe stored in C:\SharePoint
  2. Rename the report html file to our naming convention.
  3. Upload the report to a document library in SharePoint.
  4. E-mail a copy of the report to the SharePoint administrator.

Modify the variables in the script below to suit your environment. You can easily schedule this script in Windows Task Scheduler so that it generates reports periodically.

Add-PSSnapin Microsoft.SharePoint.PowerShell
Write-Host "Script starting.."
$ReportName = "c:\SharePoint\2010SPSFR.html"
$ReportNewName = "SPFarm-Config-" + $(Get-Date -Format dd-MM-yy) + ".html"
#Store a copy of the configuration file in a SharePoint library
$Web = "http://your-site"
$List = "FarmConfig"
$AdminEmail = ""
$MailServer = ""
$FromAddress = ""
#Run Automatic Documenting Program and rename the file
CD C:\SharePoint
Start-Process c:\SharePoint\2010spsfr.exe
#Give the program 40 seconds to complete report generation.
Start-Sleep 40
#Rename the report to a useful name
Rename-Item -Path $ReportName -NewName $ReportNewName
#Upload the file to SharePoint
Function UploadToSPDocLib($LocalPath,$spDocLibPath) 
$WebMethod = "PUT" 
$UploadFullPath = $spDocLibPath + $(split-path -leaf $LocalPath) 
$WebClient = new-object System.Net.WebClient 
$WebClient.Credentials = [System.Net.CredentialCache]::DefaultCredentials 
$WebClient.UploadFile($UploadFullPath, $WebMethod, $LocalPath) 
UploadToSPDocLib "c:\sharepoint\$($ReportNewName)" "$($Web)\$($List)\"
$messageParameters = @{
				Subject = "SharePoint Farm: Test - Configuration Documentation"
				Body = "Please see attached file for the SharePoint farm documentation generated on $(Get-Date -Format dd-MM-yy)"
				From = $FromAddress
				To = $AdminEmail
				SmtpServer = $MailServer
				Attachments = "c:\sharepoint\$($ReportNewName)"
			Send-MailMessage @messageParameters
Write-Host "Done."