Have these servers an OpsMgr agent installed?
Today I got a question from a customer if I would check if a number of servers had an OpsMgr agent installed?
Because this was a large list and the number of servers being monitored by OpsMgr was also a very large list I didn’t wanted to to copy and paste all the server names for the text file and check them in the OpsMgr Console.
So I created a PowerShell script to check if an OpsMgr Agent was installed for each of the servers in the file list.
The first script I created was not very fast because it did a get-agent for each of the servers in the list and that takes quite some time in a large environment ;-) So I created a new one that’s much faster.
Let’s start with the slow script:
First you need to put all the servers you want to check in a file, like this:
servername1 servername2 servername3 servername4 servername5 servername6 servername7 servername8 servername9 servername10 servername11 dc8 |
Save this list in a text file like d:\temp\servers.txt
Now run the next script in the OpsMgr Command shell:
$servers = get-content d:\temp\servers.txt
foreach ($server in $servers) {get-agent | where {$_.ComputerName -eq $server} | select Name} |
As you can see it takes almost 12 seconds to do this the slow way.
And now the fast way.
$Servers = get-content c:\temp\servers.txt $Agents = get-agent | select ComputerName Foreach ($agent in $Agents) {if ($servers –contains $agent.ComputerName) {$agent | select ComputerName}} |
So the next time someone is asking you if an OpsMgr agent is installed on their servers you now it in seconds.
Have fun using PowerShell!