基于PowerShell的windows安全基线检查开发——杀毒软件

最新项目需要检查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 
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,032评论 19 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,804评论 25 709
  • 一个赤裸的肉体,带着眼睛鼻子 蠕动在黑匣子 我不要肉体变冷 送去彩虹霞衣 操纵杆 呐喊军训口号 立正 稍息 旋转 ...
    那些花儿_miumiu阅读 324评论 3 3
  • 【禅语】 调伏身心,自有气度。在日常生活中调伏身心,在行善中调伏身心。我们在行善的过程中起了烦恼,要能够调伏,这样...
    武汉如心阅读 544评论 0 6
  • 一、王烁 写作最重要的事 1、写作的秘密就是马上写。耶鲁世界学人的写作培训课,克服畏难症的秘诀:“告诉自己,坐下来...
    Aladdin_79007阅读 203评论 0 0