$path = “C:\GreyAgents.txt”
$srvlist = Get-Content “$path”
$serviceName = “HealthService”
Foreach ($srv in $srvlist)
{
Write-host “Greyagents” : “$srv”
Invoke-Command -ComputerName $srv -Scriptblock{ Stop-Service -ServiceName ‘HealthService’}
Invoke-Command -ComputerName $srv -Scriptblock{ Remove-item -path “C:\Program Files\Microsoft Monitoring Agent\Agent\Health Service State” -Recurse}
Start-sleep -Seconds 10
Invoke-Command -ComputerName $srv -Scriptblock{ Start-Service -ServiceName ‘HealthService’}
Write-host “Cleared Cache Successfully”
}
You can also use this script I wrote:
https://github.com/v-bldrum/SCOM-Scripts-and-SQL/blob/master/Powershell/Clear-SCOMCache.ps1
LikeLike