Posted On October 30, 2019

PowerShell: Detect Antivirus Name on a Windows Machine

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Detect Antivirus Name on a Windows Machine
function getAntivirusName {  
$wmiQuery = "SELECT * FROM AntiVirusProduct"
$antivirus = Get-WmiObject -Namespace "root\SecurityCenter2" -Query $wmiQuery @psboundparameters -ErrorVariable myError -ErrorAction 'SilentlyContinue'

if($antivirus){
return $antivirus.displayName
}else{
$alternateAntivirusQuery=WMIC /Node:localhost /Namespace:\\root\SecurityCenter2 Path AntiVirusProduct GET displayName /Format:List|?{$_.trim() -ne ""}|%{$_ -replace "displayName=",""}
if ($alternateAntivirusQuery){
return $alternateAntivirusQuery
}else{
write-host "No antivirus software were detected. Hence, namespace querying errors."
$rawSearch=((get-wmiobject -class "Win32_Process" -namespace "root\cimv2" | where-object {$_.Name.ToLower() -match "antivirus|endpoint|protection|security|defender|msmpeng"}).Name | Out-String).Trim();
if($rawSearch){
return $rawSearch
}else{
return "No antivirus detected."
}
}

}
}
getAntivirusName;

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

PowerShell: Restart a Service on All Hyper-V Hosts of a Cluster

$serviceName='vmms' $clusterName='HyperV-cluster001' function restartServiceAllClusterNodes($service='vmms',$clusterName){ function restartService($serviceName){ $waitSeconds=40 $isValidProcess=try{[bool](get-service $serviceName -EA Stop)}catch{$false} if($isValidProcess){ try{ $process=Start-Process -FilePath…

Enable Serial over Ethernet

enableconfig tplatform console serialendcopy run startreload

PowerShell: Search File Contents Matching a Phrase or String

$searchDirectories='C:\users\Public\.jenkins\jobs' $searchDepth=1 $fileNameScope='*.xml' $searchString='kimconnect' # Select the files and perform the search in each file…