I'm trying to check in AD if AV is installed via PS. If I run the script below individually, it comes out correctly where it is installed and where it is not.
if ( [bool](Get-Process 'Sophos UI' -EA SilentlyContinue) ) {
$resultado="Instalado"
} else {
$resultado="Nao nstalado"
}
return $resultado
However, when taking it to AD, the script below shows everything as INSTALLED, even on machines where it is not. How to fix this error?
function verificaSophos {
if ( [bool](Get-Process 'Sophos UI' -EA SilentlyContinue) ) {
$resultado="Instalado"
} else {
$resultado="Nao nstalado"
}
return $resultado
}
$Comps= Get-ADComputer -Filter {(Enabled -eq $True)} -properties *
$CompList = foreach ($Comp in $Comps) {
[PSCustomObject] @{
Name = $Comp.Name
VerificaInstalacaoSophos = verificaSophos $Comp
DataColeta = Get-Date -Format "dd/MM/yyyy HH:mm:ss"
}
}
$CompList | Export-CSV c:\temp\sophos.csv -NoTypeInformation -Encoding UTF8
I want that the script shows correctly information.
You could change your function to accept a computer name like below and use that to invoke the command on the specified machine like:
However, the answer by js2010 is probably the easiest way.