Powershell:如何获取防病毒产品详细信息 [英] Powershell : How to get Antivirus product details

查看:64
本文介绍了Powershell:如何获取防病毒产品详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有超过 1500 台服务器.Windows 2003、2008 和 2012.我必须在这些服务器上收集防病毒软件(产品名称和版本)的详细信息.可能有多种防病毒产品.我不确定 powershell 脚本是否可以在 2003 服务器上运行.

We have over 1500 servers. Windows 2003, 2008 and 2012. I have to gather the details of antivirus(Product Name & Version) on these servers. There could be multiple antivirus product. I am not sure powershell script will work on 2003 server.

到目前为止,我尝试了以下脚本,但没有得到有用的信息.

So, far i tried below scripts but not got useful information.

$av = get-wmiobject -class "Win32_Product" -namespace "root\cimv2" `
              -computername "." -filter "Name like '%antivirus%'"

以下脚本在客户端操作系统上运行良好.

Below script is working fine on client operating system.

$wmiQuery = "SELECT * FROM AntiVirusProduct"
$AntivirusProduct = Get-WmiObject -Namespace "root\SecurityCenter2" -Query $wmiQuery  @psboundparameters # -ErrorVariable myError -ErrorAction 'SilentlyContinue'             
            Write-host $AntivirusProduct.displayName

有人可以就此给我建议吗?我正在尝试获取防病毒(产品和版本)的详细信息我需要为 win server 2003 做什么?

Can anybody advise me on this? I am trying to get the details of antivirus(Product & Version) What do i need to do for win server 2003?

推荐答案

您可以查询注册表,而不是依赖正在运行的进程:

Instead of relying on running processes, you could query the registry :

$computerList = "localhost", "localhost"
$filter = "antivirus"

$results = @()
foreach($computerName in $computerList) {

    $hive = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $computerName)
    $regPathList = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall",
                   "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"

    foreach($regPath in $regPathList) {
        if($key = $hive.OpenSubKey($regPath)) {
            if($subkeyNames = $key.GetSubKeyNames()) {
                foreach($subkeyName in $subkeyNames) {
                    $productKey = $key.OpenSubKey($subkeyName)
                    $productName = $productKey.GetValue("DisplayName")
                    $productVersion = $productKey.GetValue("DisplayVersion")
                    $productComments = $productKey.GetValue("Comments")
                    if(($productName -match $filter) -or ($productComments -match $filter)) {
                        $resultObj = [PSCustomObject]@{
                            Host = $computerName
                            Product = $productName
                            Version = $productVersion
                            Comments = $productComments
                        }
                        $results += $resultObj
                    }
                }
            }
        }
        $key.Close()
    }
}

$results | ft -au

示例输出:

Host      Product              Version   Comments
----      -------              -------   --------
localhost Avast Free Antivirus 10.4.2233         
localhost Avast Free Antivirus 10.4.2233         

这篇关于Powershell:如何获取防病毒产品详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆