Summary: Use Windows PowerShell to create a report for a Windows failover cluster.
Microsoft Scripting Guy, Ed Wilson, is here. Welcome back guest blogger, Rhys Campbell…
I’m involved in the administration of several Failover Clusters, and I wanted to be able to easily report on these and get an alert for any changes in status. Enter Windows PowerShell.
This Windows PowerShell script uses various FailoverCluster cmdlets to write information about a Windows Failover Cluster to a HTML file and copy this to a web server directory root. The script also tracks changes to the state of the cluster and sends an email notification with the details. The following steps outline the process to set up this script.
1. Open clstr.ps. We need to change the SMTP details here. Change the following line…
sendEmail "smtp.domain.co.uk" 8025 $subject $report $transcript "email@example.com" "firstname.lastname@example.org";
sendEmail "your.smtp.server" 25 $subject $report $transcript "email@example.com" "firstname.lastname@example.org";
Save and close the file.
2. Create a folder somewhere that is appropriate for the Windows PowerShell script and other resources, for example c:\tmp. This should be fully writable for the user who will execute the .ps1 file.
3. Now we are ready to test the execution of the script. The script is executed with three parameters inside a Windows PowerShell console:
C:\tmp\clstr.ps1 <cluster name> c:\tmp\ c:\path\to\web\server\root\
Note The cluster name refers to the Windows Failover Cluster name, not the SQL instance name. Parameter 2 should be the script directory root. Parameter 3 should be the root of your web server HTML directory. Notice the trailing slashes.
If you execute this a couple of times, the script root folder should look something like this:
The script uses the text file to keep track of the cluster state and what has changed. If you have multiple clusters, you can set this up for each one. In this situation, I recommend setting up a directory structure similar to this:
and so on...
4. After your setup is working, the final step is to create a scheduled task to run this job at your desired interval. To execute the script in Task Scheduler:
For the complete Windows PowerShell script and demo cluster HTML report, see Failover Cluster Report and state change alerter in the Script Center Repository.
Thank you, Rhys, for sharing your time and knowledge.
I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at email@example.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.
Ed Wilson, Microsoft Scripting Guy