【问题标题】:Detect and uninstall antivirus检测并卸载防病毒软件
【发布时间】:2018-10-23 21:10:17
【问题描述】:

我一直在尝试制作一个powershell脚本来检测安装了什么杀毒软件,然后卸载它。

我已经能够检测到使用 WMI 安装了哪些防病毒软件。

但是我找不到通过 powershell 卸载杀毒软件的方法。

有没有办法做到这一点? 希望大家帮忙。

我用来检测杀毒的脚本:

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         
            [array]$AntivirusNames = $AntivirusProduct.displayName       
            Switch($AntivirusNames) {
                {$AntivirusNames.Count -eq 0}{"No Antivirus installed";Continue}
                {$AntivirusNames.Count -eq 1 -and $_ -eq "Windows Defender"} {"Only Windows Defender is installed!";Continue}
                {$_ -ne "Windows Defender"} {"Antivirus installed ($_)."}
           }
} 
     END { 
         } 
}

$av = Get-AntivirusName

Add-Type -AssemblyName PresentationFramework
[System.Windows.MessageBox]::Show($av,'Antivirus')

【问题讨论】:

  • 您没有显示任何您自己的代码或任何您尝试研究/搜索解决方案的迹象。 (即使代码不起作用,也要始终包含您的代码!)我建议您阅读How to Ask 和question checklist,因为目前您的问题缺少提出问题时所期望的基础知识。您的问题可能会被否决并关闭,直到您包含基础知识。
  • 我还没有做任何事情来做这件事,因为我找不到做这件事的方法。我确实有一个检测防病毒软件的代码,但我认为谈论你可以做到这一点的方法并不重要。如果我错了,我的错

标签: powershell uninstallation antivirus


【解决方案1】:

您可以尝试以下操作,来自https://community.spiceworks.com/scripts/show/3161-detect-and-remove-software-powershell:

################################################
# Powershell Detect and Remove software script #
#                                              #
# V1.0 - Gav                                   #
################################################
# - Edit the Variables below and launch the    #
#   script as an account that can access the   #
#   machines.                                  #
# - Script will check that logs exist and      #
#   create them if needed.                     #
################################################

cls

#VARIABLES - EDIT BELOW
    $software = "INSERT SOFTWARE HERE" # - Enter the name as it appears from WMIC query. WMIC PRODUCT NAME
    $textfile = "C:\path\pclist.txt"
    $Successlogfile = "C:\path\Done_Machines.txt"
    $Errorlogfile = "C:\path\Failed_Machines.txt"

#Date Calculation for Logs
    $today = Get-Date
    $today = $today.ToString("dddd (dd-MMMM-yyyy)")

#Load PC's From Text File
    $computers = Get-Content "$textfile"

#Check if Log Files Exist
    If (Test-Path $Successlogfile) {
        Write-Host -ForegroundColor Green "Success Log File Exists, Results will be appended"
                                   }
        else
                                   {
        Write-Host -ForegroundColor Red "Success Log File does not exist, creating log file"
        New-Item -path $Successlogfile -ItemType file
                                   }

    If (Test-Path $Errorlogfile) {
        Write-Host -ForegroundColor Green "Error Log File Exists, Results will be appended"
                                   }
        else
                                   {
        Write-Host -ForegroundColor Red "Error Log File does not exist, creating log file"
        New-Item -path $Successlogfile -ItemType file
                                   }



#Run Ping Test and Uninstall if turned on
    foreach ($computer in $computers) {
        If (Test-Connection -quiet -ErrorAction SilentlyContinue -computername $computer -count 2) 
        {
                Write-Host -ForegroundColor Green "$Computer is responding, Attempting Uninstall of $Software"
                Add-Content $Successlogfile "`n$today`n$Computer`n"
                Get-WmiObject -class Win32_Product -ComputerName $computer | Where-Object {$_.Name -match $software} | ForEach-Object { $_.Uninstall()}
        }
            else
        {
                Write-Host -ForegroundColor Red "$Computer is not responding"
                Add-Content $Errorlogfile "`n$today`n$Computer`n"
        }
                                       }

【讨论】:

  • 如果你要复制和粘贴someone else's code without attribution,至少要花时间格式化它,这样它才能正确显示。
  • @JamesC。它经过了适当的编辑......而且我确实提到它不是我的工作......
  • 你知道有一个edit history for your answer吗?因此,当我大约两周前评论和编辑您的帖子时,任何人都可以看到这些事情都不是真的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-08
  • 1970-01-01
  • 2010-10-13
  • 2012-04-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多