最新项目需要检查windows servers 2008、2012操作系统是否安装了杀毒软件,看了网上的实现方式,发现stackoverflow上有实现的方式,但是只是过滤antivius,多增加一个过滤中文词"杀毒"就能实现查询操作系统是否安装了杀毒软件。代码如下:
$computerList = "localhost"
$filter_en = "antivirus"
$filter_ch="杀毒"
$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_en) -or ($productName -match $filter_ch)) {
$resultObj = [PSCustomObject]@{
Host = $computerName
Product = $productName
Version = $productVersion
Comments = $productComments
}
$results += $resultObj
}
}
}
}
$key.Close()
}
}
$results
网友评论