PowerShell: obtención del estado de Windows Defender de todas las computadoras unidas al dominio (Get-AntiMalwareStatus)
¿Está utilizando Windows 10 y Windows Server 2016 o superior? ¿Quiere comprobar el estado de Windows Defender Anti-Malware desde todas las computadoras? Entonces has venido al lugar correcto. Te daré una herramienta para hacer precisamente eso.
La meta
Sin hablar mucho, esto es lo que es posible con una función avanzada de PowerShell llamada Get-AntiMalwareStatus.
Get-AntiMalwareStatus -Scope AllServer | Format-Table -AutoSize
Genial, ¿ja?
Sin Format-Table, la salida se muestra en formato de lista. A continuación se muestra un ejemplo de cómo obtener el estado del malware de todas las computadoras unidas al dominio.
Los valores posibles para el parámetro de alcance son:
- AllServer=Todo el dominio unido a Windows Server
- AllComputer=Todo el dominio se unió a la computadora con sistema operativo Windows
Si no se proporciona ningún parámetro de alcance, la función muestra el estado de Defender de la computadora local.
Todo lo que necesita es un dominio de Active Directory y si desea recuperar información de Windows Defender de los equipos cliente, debe habilitar WinRm en todos los sistemas operativos del cliente como se describe aquí: Grupo Políticas: Habilitación de WinRM para sistemas operativos de cliente Windows (Windows 10, Windows 8, Windows 7).
La función Get-AntiMalwareStatus
Para utilizar esta función en su sesión de PowerShell, pase al siguiente punto.
function Get-AntiMalwareStatus {
# .SYNOPSIS
# Get-AnitMalewareStatus is an advanced Powershell function.
# It gets the Windows Defender Status of the local computer and remote computer.
# .DESCRIPTION
# Uses Invoke-Command and Get-MpComputerStatus.
# .PARAMETER
# Scope
# Define a scope. Possible values:
# AllServer, AllComputer
# Default: localhost
# .EXAMPLE
# Get-AntiMalwareStatus -Scope AllComputer
# .NOTES
# Author: Patrick Gruenauer
# Web: https://sid-500.com
[CmdletBinding()]
param
(
[Parameter(Position=0,Helpmessage = 'Possible Values: AllServer, AllComputer')]
[ValidateSet('AllServer','AllComputer')]
$Scope
)
$result=@()
$ErrorActionPreference="SilentlyContinue"
switch ($Scope) {
$null {
Get-MpComputerStatus | Select-Object -Property Antivirusenabled,AMServiceEnabled,AntispywareEnabled,BehaviorMonitorEnabled,IoavProtectionEnabled,`
NISEnabled,OnAccessProtectionEnabled,RealTimeProtectionEnabled,AntivirusSignatureLastUpdated
}
AllServer {
$server=Get-ADComputer -Filter 'operatingsystem -like "*server*" -and enabled -eq "true"' | Select-Object -ExpandProperty Name
foreach ($s in $server) {
$rs=Invoke-Command -ComputerName $s {Get-MpComputerStatus | Select-Object -Property Antivirusenabled,AMServiceEnabled,AntispywareEnabled,` BehaviorMonitorEnabled,IoavProtectionEnabled,NISEnabled,OnAccessProtectionEnabled,RealTimeProtectionEnabled,AntivirusSignatureLastUpdated}
If ($rs) {
$result+=New-Object -TypeName PSObject -Property ([ordered]@{
'Server'=$rs.PSComputername
'Anti-Virus'=$rs.AntivirusEnabled
'AV Update'=$rs.AntivirusSignatureLastUpdated
'Anti-Malware'=$rs.AMServiceEnabled
'Anti-Spyware'=$rs.AntispywareEnabled
'Behavior Monitor'=$rs.BehaviorMonitorEnabled
'Office-Anti-Virus'=$rs.IoavProtectionEnabled
'NIS'=$rs.NISEnabled
'Access Prot'=$rs.OnAccessProtectionEnabled
'R-T Prot'=$rs.RealTimeProtectionEnabled
})
}
}
}
AllComputer {
$comp=Get-ADComputer -Filter 'enabled -eq "true"' | Select-Object -ExpandProperty Name
foreach ($c in $comp) {
$rs=Invoke-Command -ComputerName $c {Get-MpComputerStatus | Select-Object -Property Antivirusenabled,AMServiceEnabled,AntispywareEnabled,` BehaviorMonitorEnabled,IoavProtectionEnabled,NISEnabled,OnAccessProtectionEnabled,RealTimeProtectionEnabled,AntivirusSignatureLastUpdated}
If ($rs) {
$result+=New-Object -TypeName PSObject -Property ([ordered]@{
'Computer'=$rs.PSComputername
'Anti-Virus'=$rs.AntivirusEnabled
'AV Update'=$rs.AntivirusSignatureLastUpdated
'Anti-Malware'=$rs.AMServiceEnabled
'Anti-Spyware'=$rs.AntispywareEnabled
'Behavior Monitor'=$rs.BehaviorMonitorEnabled
'Office-Anti-Virus'=$rs.IoavProtectionEnabled
'NIS'=$rs.NISEnabled
'Access Prot'=$rs.OnAccessProtectionEnabled
'R-T Prot'=$rs.RealTimeProtectionEnabled
})
}
}
}
}
Write-Output $result
}
Cómo usarlo
Copie el código anterior en PowerShell ISE (ise.exe) y ejecute el código. Luego escribe el comando y diviértete con él.
Si desea que la función esté disponible permanentemente, de modo que esté disponible cada vez que inicie PowerShell, debe crear una carpeta en C:\Program Files\WindowsPowerShell\Modules. Asigne a la carpeta el nombre Get-AntiMalwareStatus. Luego guarde el código como archivo .psm1 en esa carpeta. La siguiente captura de pantalla te ayudará.
¡Hasta la próxima, nuevamente con PowerShell!



