I'm creating a PowerShell script to list down all the AV installed on a machine. I wanted to exclude the Windows Defender on the "If" statement when doing the checks. Below is my script:
default
{
$result1 = 'There are {0} AV products installed on this system' -f $AVList.Count
$result2 = 'DisplayNames = {0}' -f ($AVList.displayName -join ', ')
if (Select-String -Path $workingdirectory\AVList.txt -Pattern $AVList.displayName -Exclude 'Windows Defender' -SimpleMatch -Quiet){
$writeTxt4 = ("$(Get-Date) - [INFO]",'There are {0} AV products installed on this system.' -f $AVList.Count)
$writeTxt5 = ("$(Get-Date) - [INFO]",'Anti-Virus Names = {0}' -f ($AVList.displayName -join ', '))
Write-Output $writeTxt4 $writeTxt5
Add-Content -path $report $writeTxt4
Add-Content -path $report $writeTxt5
}else{
$writeTxt4 = ("$(Get-Date) - [INFO]",'There are {0} AV products installed on this system. Smile.' -f $AVList.Count)
$writeTxt5 = ("$(Get-Date) - [INFO]",'Anti-Virus Names = {0}' -f ($AVList.displayName -join ', '))
Write-Output $writeTxt4 $writeTxt5
Add-Content -path $report $writeTxt4
Add-Content -path $report $writeTxt5
}
I tried to exclude it but still unable to make it work. Thank you so much for your help.
$AVList.displayNamecontainsWindows Defenderthen what you are doing won't work. By the way, this is not a minimal reproducible example.$AVList.displayNamecontainsWindows Defender. any idea how can I exclude it from the condition? Also, that's the main goal of my concern. thank you.$AVList.displayNameto all elements where they don't match "Windows Defender" before passing it toSelect-String