最新項(xiàng)目需要檢查windows servers 2008、2012操作系統(tǒng)是否安裝了殺毒軟件诫尽,看了網(wǎng)上的實(shí)現(xiàn)方式慈省,發(fā)現(xiàn)stackoverflow上有實(shí)現(xiàn)的方式,但是只是過(guò)濾antivius略板,多增加一個(gè)過(guò)濾中文詞"殺毒"就能實(shí)現(xiàn)查詢(xún)操作系統(tǒng)是否安裝了殺毒軟件毁枯。代碼如下:
$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