Some time ago I got asked to write some PowerShell code to list all servers which have an Operations Manager agent installed.
So, how does one accomplish this?
The nice and proper way would be to query Add/Remove Programs, right?
function Get-NoOpsMgrAgent { import-module activedirectory get-adcomputer -filter {operatingsystem -like "*server*"} | foreach { $Test = Test-Connection -ComputerName $_.Name -Quiet if ($Test -eq $true) { $result = Get-WmiObject -ComputerName $_.Name Win32Reg_AddRemovePrograms -ErrorAction silentlycontinue | where {$_.DisplayName -like "*operations manager*agent"} | select displayname if ($result -eq $null) { $_.Name } } } }
Though I notices that some systems gave me an error. Mainly some Windows Server 2003 machines, but nevertheless I still wanted to list those too!
So, what would be a nice way to check this?
Well, what about going back to basics… test if the installation path exists Image may be NSFW.
Clik here to view.
function Get-NoOpsMgrAgentPath { import-module activedirectory get-adcomputer -filter {operatingsystem -like "*server*"} | foreach { $Test = Test-Connection -ComputerName $_.Name -Quiet if ($Test -eq $true) { $result = Test-Path ('\\'+$_.Name+'\c$\Program Files\System Center Operations Manager\Agent') if ($result -eq $false) { $_.Name } } } }
Alright. Now that I’ve got two ways of checking this I feel pretty save that servers existing in both lists don’t have the OpsMgr agent installed.
Servers that only exist in the output of Get-NoOpsMgrAgentPath would be older operating systems.
… and servers that only exist in the output of Get-NoOpsMgrAgent would be servers to take a look at and see what’s going on Image may be NSFW.
Clik here to view.