PowerShell Script: SCCM Health Check
30/01/2012: This script has been updated to version 3.5. Details can be found HERE. The download link on this article has also been updated to version 3.5.
26/05/2011: Version 3.3 has been posted here. The download link to the script on this post is also updated to the new version 3.3.
21/04/2011: Please be advised that I have posted a newer version of the script here. The existing script download link on this page has also been updated to point to the newer version. For the chanages in newer version, please refer to my updated post.
Over the last few months, I have been working on a PowerShell script to perform some health check activities for a customer’s entire SCCM environment. This is to provide a snapshot of health state of some elements of SCCM environment at a point of time since there is no SCOM in that environment to monitor SCCM at this stage.
The script checks the following:
- Ping check all servers in the SCCM infrastructure
- If first ping fails, wait for number of seconds (defined in XML file) then attempts to ping few more times (Number of retries defined in XML file).
- if returns any successful pings, ping test is classified as success.
- DNS name resolution check for all servers in SCCM infrastructure
- forward lookup check
- reverse lookup check
- compare DNS A record with the FQDN that's set on the server
- All site systems in warning or critical state
- All site components in warning or critical state
- All package distribution with issues
- Checks all Non-PXE boot image packages in PXE DP share
- Checks any inboxes that contain number of files that's over the threshold (threshold is set in the XML file)
- Checks availability of Inbox folders on all primary site servers
- Checks SCCM site backups on all primary sites within the "DaysToCheck" that's set in XML file.
- Checks any errors in SQL server and SQL agent logs
- Checks Application logs on SQL servers for any SQL related errors.
What’s included in this script:
- SCCM-HealthCheck.ps1: the actual PowerShell script
- Health-Check.xml: contains all configuration settings for the script. this file needs to be modified to suit your environment before running the script.
- DIRUSE.exe: This is from Windows 2000 Resource Kit (http://support.microsoft.com/kb/927229). it is used to retrieve SCCM inboxes information. I have chosen to use this rather than the native PowerShell cmdlet Get-ChildItem because DIRUSE.EXE retrieves the information much faster against remote servers than Get-ChildItem.
Configuring the script:
The health check script reads all the settings from Health-Check.xml which is located in the same folder as the script.
You’ll need to Configure the XML according to the following:
Note: If you are having trouble reading the text on above image, this image can be download here
- The script has the option to email out the health check report (can be switched on and off in XML file)
- The email body is in HTML format that contains the overall status of each check.
- The detailed report is in TXT format and it is attached to the email. it is also located in the same folder as the script with the timestamp. if emailing is turned off, the detailed report can be located there.
Below is a sample HTML email body generated from my test environment:
- The PowerShell execution policy on the computer that's running the script needs to be set to at RemoteSigned or Unrestricted.
- The account used to run this script needs to have:
- local admin rights on Central site server, Central site provider server (if not the site server itself)
- In the SQL servers, sysadmin rights or at least access to the master DB on all SQL servers to be able to read SQL server and agent logs.
- SMS admin access on all primary sites
- NTFS read permission to "inboxes" folders on all primary site servers.
- Scheduling the script in Windows Task Scheduler:
- "Allow log on as batch job" rights is required for the user account to run scheduled jobs.
- if scheduling in Windows 2008 or later, please make sure "Run with highest privileges" is ticked to bypass UAC (User Account Control)
- The operating system for SQL servers has to be Windows 2008 or later. This is because Get-WinEvent is used to read event log rather than using Get-EventLog because Get-EventLog does not support server side filtering. Therefore Get-WinEvent is used to improve performance when reading remote event logs. However, Get-WinEvent only works on Vista and later version of Windows.
- PowerShell Version 2 is required to run the script.
I’m planning to re-write some part of the script to give us an option to utilise PowerShell Remoting wherever is suitable. This will greatly improve the performance of the script (especially when gathering inboxes information across the WAN link). When this is done, Get-ChildItem can be used and executed locally on each site servers and eliminate the needs for DIRUSE.EXE.
I’ll get this done in the next few weeks and post it here once it’s done.
Leave a comment