Powershell:查找已安装的防病毒软件,过滤掉 Windows Defender [英] Powershell: Find installed Antivirus, filtering out Windows Defender

查看:132
本文介绍了Powershell:查找已安装的防病毒软件,过滤掉 Windows Defender的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部.

我有一个 PowerShell 脚本,可以检测安装在 Windows 中的防病毒软件(这实际上很常见).问题是,我希望它过滤 Windows Defender,特别是因为安装了 Windows 8、8.1 和 10.如果存在唯一的防病毒软件,我希望我的脚本指示 Windows Defender 是否存在,如果存在则给出不同的输出.

I have a PowerShell script which will detect antivirus software installed in Windows (it's actually fairly common). The problem is, I want it to filter Windows Defender, especially since Windows 8, 8.1, and 10 come with it installed. I want my script to indicate whether or not Windows Defender if the ONLY antivirus software present and give a different output if it is.

这是我目前所拥有的...

Here's what I have so far...

function Get-AntivirusName { 
[cmdletBinding()]     
param ( 
[string]$ComputerName = "$env:computername" , 
$Credential 
) 
    BEGIN  
        { 
            $wmiQuery = "SELECT * FROM AntiVirusProduct" 
        } 
    PROCESS  
        {    
            $AntivirusProduct = Get-WmiObject -Namespace "root\SecurityCenter2" -Query $wmiQuery  @psboundparameters         
            $AntivirusNames = $AntivirusProduct.displayName       
            if ($AntivirusNames -eq "") {
                Write-host "Anti-Virus is NOT installed!"
            } 
            elseif ($AntivirusNames -eq "Windows Defender") {
                Write-host "ONLY Windows Defender is installed!"
            }
            else {
                Write-host "Anti-Virus is installed (" + $AntivirusNames + ")."
            }

        } 
     END { 
         } 
}

Get-AntivirusName 

结果是,无论安装了哪些其他防病毒软件应用程序,它一直告诉我只安装了 Windows Defender.有人可以指出我遗漏了什么吗?

The result is, no matter which other antivirus software apps are installed, it keeps telling me only Windows Defender is installed. Can someone point out what I'm missing?

非常感谢!

推荐答案

我的猜测是它正在检查 elseif 语句中数组的每个元素,因此即使有多个结果也是如此.您可以添加一个条件,即只有一个结果,如下所示:

My guess is it's checking each element of the array in the elseif statement so is true even if there are multiple results. You could add a condition that there is just one result as follows:

elseif ($AntivirusNames -eq "Windows Defender" -and $AntivirusNames.count -eq 1) {
                Write-host "ONLY Windows Defender is installed!"
            }

这篇关于Powershell:查找已安装的防病毒软件,过滤掉 Windows Defender的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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