Friday, 17 April 2015

Using PowerShell to Repair SCOM Agents

Quite often after installing Operations Manager Roll-ups you may notice that even after updating all of your managed Agents some still report as being on the wrong patch level.


This is often common and can be frustrating so I knocked up this little script that will run a repair on the agents and (hopefully) resolve the issue.

If (!(Get-Module -Name OperationsManager))

{

    Import-Module -Name OperationsManager

}



$Creds = Get-Credential

$Rollup = "*UR5*"



New-SCManagementGroupConnection -Credential $Creds -ComputerName YOURSCOMSERVER



[Array]$AgentstoUpdate = Get-SCOMAgent |

Where-Object -FilterScript {

    ($_.Patchlist -notlike $Rollup) -and ($_.Patchlist -notlike '')

} |

Select-Object -Property DisplayName , PatchList



Foreach ($i in $AgentstoUpdate)

{

    Try

    {

        Write-Output 'Submitting Repair Request for ' $i.DisplayName

        Get-SCOMAgent -DNSHostName $i.DisplayName | Repair-SCOMAgent -Actionaccount $Creds

    }

    Catch

    {

        Write-Output 'Failed to Submit Repair Request for ' $i.DisplayName

    }

}

No comments:

Post a Comment

Blog Archive