Since you're talking of 15,000 hosts, querying each of them from the network is going to be highly inefficient.
The Right Thing To Do™ then is to have a watchdog running on each host to make sure the appropriate software is installed and running. This watchdog might be a piece of software running as a service, a scheduled script or even hardware-based if you use something like Intel vPro.
To verify if an AV software is installed, you could use the following PowerShell command --
$avSoftware = get-wmiobject -class "Win32_Product" -namespace "root\cimv2" `
-computername "." -filter "Name like '%antivirus%'"
Note that at the end you have a filter
argument that you can customize to make sure you're looking at the right product.
After playing a bit with the like
operator, you should be able to nail the antivirus description and minor variations here and there. Note that my example above (anything containing the word "antivirus") is pretty simplistic. You should instead look for specific patterns matching your approved antivirus software (e.g. "Trend Micro Antivirus%")
Anyway, the command above will return a collection of installed products that match your filter
statement. From here you can test whether $avSoftware.Count
is greater than zero, in which case you have antivirus software installed. The example below lists all the installed antivirus software --
if ($avSoftware.Count -gt 0) {
foreach ($av in $avSoftware) {
write-host $p.Name
}
} else {
write-host "No AV software found"
}
Instead of just printing a message saying that no AV has been found, you should obviously do something more useful, e.g.
- Notify an admin
- Install an AV from the network
You also said you'd like to get the version of the installed AV. To do that, you can use the Version
property of the Win32_Process
. Let's modify the above code like this to also print the version numbers for the installed software --
$avSoftware = get-wmiobject -class "Win32_Product" -namespace "root\cimv2" `
-computername "." -filter "Name like '%antivirus%'"
foreach ($av in $avSoftware) {
write-host $av.Name, $av.Version
}
As for the version of the installed virus definition files, you'd have to rely on each specific AV WMI interface. You'll have to consult the vendor's documentation for that.
One more thing to remember. It's probably not enough to know that the host has AV installed if the AV isn't running. After checking which AV is installed, you should make sure its process is running. To do that, you'll have to know what the appropriate process for each of your AV software is and look for them like this --
$processes = get-wmiobject -class "Win32_Process" -namespace "root\cimv2" `
-computername "." -filter "Name = 'TeaTimer.exe'"
if ($processes.Count -gt 0) {
foreach ($p in $processes) {
write-host $p.Name
} else {
# AV not running. Launch it here or notify someone
}
The above example looks for the Spybot process (not exactly AV, but you get the picture), which is called "TeaTimer.exe". Modify it to look for your process instead.
Now, all of that said, if you're dealing with thousands of hosts like that, you should probably invest in some management tool (e.g. LANdesk, Microsoft System Center or Level Platforms.) These tools would make your life a whole lot easier.