*Update* This script needs updating and is yet to be moved to GitHub. I’m working on moving this to Proactive Remediations in Microsoft Intune. Stay tuned. *Update*
The SCCM Client Health Monitor Script is a Powershell script which fixes common issues related to SCCM client health.
The script is currently capable of fixing following issues:
- SCCM client stuck in Provisioning Mode
- Corrupt Group Policy files (Registry.pol)
- BITS transfers with errors
- SCCM client service not running
- SCCM client service disabled
- No SCCM client installed
Further to fixing the mentioned issues, the script also supports sending an e-mail or a status to Microsoft Teams if any issues are found. All actions are logged to a local log file: SCCM-ClientHealthMonitor.log in the CCM\Logs folder.
.\SCCM-ClientHealthMonitor.ps1 -TestProvMode -TestGPOFiles
This will run tests and try to fix issues related to provisioning mode and corrupt group policy files.
.\SCCM-ClientHealthMonitor.ps1 -TestSCCMClient -InstallSCCMClient
This will test for a running ccmexec service and try to start the service if it’s not running. If the service doesn’t exists, the script will try to install the SCCM client.
.\SCCM-ClientHealthMonitor.ps1 -TestProvMode -TestGPOFiles -TestBITS -TestSCCMClient -InstallSCCMClient -EmailStatus -TeamsStatus
This will run the script with all available options.
The e-mail being sent with the -EmailStatus parameter looks like below example.
The status messages being sent with the -TeamsStatus parameter will look like below examples.
- Note: This is done with help from the PSTeams module. Find a lot more details on the use here: https://github.com/EvotecIT/PSTeams.
The SCCM-ClientHealthMonitor.log file will look like below example when opened with CMtrace.
- The script requires local administrative rights to run
- Modify the script. I have made a comment with # EDIT here the places that needs editing
- Modify the -EmailStatus part with your own details such as SMTP server, recipient etc.
- Modify the -TeamsStatus part with your own details such as URL for webhook, title, text etc.
- Modify the Install-SCCMClient function with MP and site code details
Running the Script
The best option to run the script, is to do so with a scheduled task.
- Running as SYSTEM
- Trigger: Running at log on of any user
- Action: Starting powershell.exe with argument: -ExecutionPolicy Bypass -File “\\ServerShare\SCCM-ClientHealthMonitor.ps1” -TestProvMode -TestGPOFiles -TestBITS -TestSCCMClient -InstallSCCMClient -EmailStatus -TeamsStatus
- 1.0 – Script created
- 2.0 – Added TestBITS, TestSCCMClient and InstallSCCMClient
- 3.0 – Added TeamsStatus, making the script able to send status notifications to Microsoft Teams
- 3.1 – Minor changes to $ComputerModel as well as added more commenting
I haven’t done the best commenting job in the script itself, so please let me know in the comment section down below if you need any assistance. 🙂
And of course, it goes without saying, but test this thoroughly before putting to use in production.
Also, if you are looking for more details on how to prepare Microsoft Teams for receiving notifications, please take a look at this great post by Michael Mardahl: https://www.scconfigmgr.com/2019/07/10/how-to-notify-a-microsoft-teams-channel-when-a-new-windows-device-has-enrolled-in-microsoft-intune/