Restart the SCCM client service on a remote computer
Restart the CcmExec service (SMS Agent Host) on one or more remote computers through PowerShell remoting and report the new status.
LanguagePowerShell
What it does to the systemMakes changes. Test it on one computer first.
An SCCM client hangs on a download or stops answering. A restart of the SMS Agent Host service often gets it going again.
This script restarts the CcmExec service on each computer you name. It returns the status of the service after the restart.
PowerShell
<#
Restart the SCCM client service (CcmExec) on remote computers.
Needs WinRM on the target and local administrator rights there.
Example: .\Restart-CcmExec.ps1 -ComputerName PC01, PC02 -WhatIf
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[Parameter(Mandatory = $true)]
[string[]]$ComputerName
)
foreach ($computer in $ComputerName) {
if (-not $PSCmdlet.ShouldProcess($computer, 'Restart service CcmExec')) { continue }
$row = [ordered]@{ ComputerName = $computer; Status = ''; Error = '' }
try {
# The script block runs on the remote computer.
$row.Status = Invoke-Command -ComputerName $computer -ErrorAction Stop -ScriptBlock {
Restart-Service -Name CcmExec -Force -ErrorAction Stop
(Get-Service -Name CcmExec).Status.ToString()
}
}
catch {
$row.Error = $_.Exception.Message
}
[pscustomobject]$row
}
How to use it
- Save the script as
Restart-CcmExec.ps1. - Open PowerShell with an account that is a local administrator on the target computers.
- Run
.\Restart-CcmExec.ps1 -ComputerName PC01 -WhatIfto see what it would do. - Run it again without
-WhatIf. Test on one computer first. - For a list, use
-ComputerName (Get-Content C:\Temp\computers.txt).
Good to know
- A restart stops running installs and downloads on that client. Do not use it in the middle of a deployment.
- The client needs a minute or two after the restart before it answers actions again.
CcmExec
SMS Agent Host
restart service
Invoke-Command
remoting