Querying AD for Computers that do not have a SCOM Agent

Today I was having a chat about SCOM Agents with a couple of colleagues and the subject turned to finding out if every server that is in AD actually has an agent installed. I’m certain there are people out there that have their own solution but I thought why not just query AD for the computer objects for these servers and compare that list against the agents in SCOM…should be pretty simple.

If anyone has a better solution (and I’m sure you do)…feel free to share it.


# This script will query AD for any computer object that is running Windows Server and compare it against the agents in SCOM

Import-Module ActiveDirectory
$adcomputers = get-adcomputer -Filter { OperatingSystem -like “*Windows Server*” -AND ObjectClass -eq “Computer” } | Select -ExpandProperty Name | Sort Name

# There is a lot of whitespace…let’s get rid of it
$serverlist = $adcomputers | foreach {$_.TrimStart()} | Foreach {$_.TrimEnd()}

# Get a list of SCOM Agents
$agents = Get-Agent | select Computername
$count = 0

# Loop through the list of servers in AD and check if it’s in SCOM
foreach ($server in $serverlist)
if (!($agents | ? {$_.ComputerName -eq $server}))
Write-Host “There is no agent on $server”
Write-Host “There are $count servers without an agent”

Obviously this is a very raw script that I knocked up in just a few minutes, but it does the job fine. If you wanted to extend it, you could easily take the results of this script and push out the agent automatically to those servers that don’t have the SCOM Agent.


working perfectly as described, just one typo here – instead get-agent it should be get-SCOMagent

Hello. You’re 100% right in SCOM 2012 the cmdlet should be Get-SCOMAgent. I actually was in a 2007 environment at the time which I probably should have mentioned. Good pickup though, I appreciate your comment. Have a great day!

Also if you just run the Discovery Wizard, it will give you all the machines without agent installed.

Hello 🙂
Just change Get-Agent / Get-SCOMAgent and change double quotes / single quotes in -Filter { OperatingSystem -like ‘*Windows Server*’ -AND ObjectClass -eq ‘Computer’ } and script works perfectly ( ^^)

Leave a Reply