PowerShell, SCOM

Manually clearing your SCOM agent cache

There are occasions when a SCOM agent goes into a “not monitored” or “gray” state, to troubleshoot this we normally perform a “clear cache” of the agent.

pic1

I have created a simple script that clears the cache on the monitored server agent, this script can be run both locally and remotely.

The script will do the following steps:

1. Stop the Microsoft Monitoring Agent service.

2. Check the Microsoft Monitoring Agent service status.

3. Rename the existing “Health Service State” folder.

4. Start the Microsoft Monitoring Agent service.

5. Check the Microsoft Monitoring Agent service status.

6. Remove the old “Health Service State” folder.

7. Done.

The Script

[powershell]
$Server = Read-Host "Please enter your server name"
$Service = Get-Service -Name HealthService -ComputerName $Server

Write-Host "`n1. Stopping the Monitoring Agent service…`n"

Stop-Service $Service

Write-Host "2. Checking the Monitoring Agent service status:"

Write-Host "`nMonitoring Agent service status: "-nonewline; Write-Host $Service.Status -Fore Red

Start-Sleep -s 3

Write-Host "`n3. Renaming the existing ‘Health Service State’ folder to ‘Health Service State Old’ `n"

Rename-Item -Path "\\$Server\C$\Program Files\Microsoft Monitoring Agent\Agent\Health Service State" -NewName "Health Service State Old"

Write-Host "4. Starting the Monitoring Agent service…`n"

Start-Service $Service

Start-Sleep -s 3

Write-Host "5. Checking the Monitoring Agent service status:"

Write-Host "`nMonitoring Agent service status: "-nonewline; Write-Host $Service.Status -Fore Green

Write-Host "`n6. Removing the ‘Health Service State Old’ folder."

Remove-Item -Path "\\$Server\C$\Program Files\Microsoft Monitoring Agent\Agent\Health Service State Old" -Recurse

Write-Host "`n7. Done!"
[/powershell]

Download the script from here:
SCOM Agent Clear Cache

3 thoughts on “Manually clearing your SCOM agent cache”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s