Flushing a SCOM Agent Cache using PowerShell

How can I flush an Agent Cache using PowerShell was the question of the day… ok, plenty of ways to do that, but here’s a basic pointer in the right direction. Remember, you’ll want to stop the healthservice first, and start it after this code has run…

# The name of the Health Service State folder where the Config is downloaded to/stored on an Agent.
$MMAgentHSTFolder = “Health Service State”

# Retrieve the path of the installation folder for the SCOM Agent from the registry.
$reg = Get-ItemProperty -Path “HKLM:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Setup\”
$MMAgentInstallDirectory = $reg.InstallDirectory

# Populate the full path to the folder.
$MMAgentHSTPath = $MMAgentInstallDirectory + $MMAgentHSTFolder

# Delete all of the files in the Health State Folder and any subdirectories.
Remove-Item -Path $MMAgentHSTPath\* -recurse


Health Service State Empty














Of course, if you prefer to do this all on one line you could easily do that too…have fun!


Thanks for the script. It really helps as this is most common issue in SCOM.
I did use your script and modified to stop and start service using powershell.

Using powershell, invoke command on remote machine. It will stop service, wait for 5 seconds before checking for service status. If service is stopped, then delete folder. Restart service after.

here is my script

$MachineName = “Test.domain.net”
Invoke-Command -ComputerName $MachineName -ScriptBlock {
$MMAgentHSTFolder = “HealthService”
$MMAgentHSTPath = ((Get-ItemProperty -Path “HKLM:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Setup\”).InstallDirectory) + $MMAgentHSTFolder
Stop-Service $MMAgentHSTFolder
start-sleep -s 5
if ((Get-Service $MMAgentHSTFolder).Status -eq “Stopped”)
remove-item $MMAgentHSTPath -force -Recurse
Start-Service $MMAgentHSTFolder
Get-Service $MMAgentHSTFolder

Trackbacks for this post

Leave a Reply