Weboldal keresés

PowerShell: A Windows Defender állapotának lekérése minden tartományhoz csatlakozó számítógépről (Get-AntiMalwareStatus)


Windows 10 és Windows Server 2016 vagy újabb rendszert használ? Minden számítógépen szeretné ellenőrizni a Windows Defender Anti-Malware állapotát? Akkor a megfelelő helyre jöttél. Ehhez adok egy eszközt.

A cél

Sok beszéd nélkül, íme, mi lehetséges a Get-AntiMalwareStatus nevű fejlett PowerShell-függvénnyel.


Get-AntiMalwareStatus -Scope AllServer | Format-Table -AutoSize

Klassz, ha?

Format-Table nélkül a kimenet lista formátumban jelenik meg. Íme egy példa a rosszindulatú programok állapotának lekérdezésére az összes domainhez csatlakozó számítógépről.

A hatókör paraméter lehetséges értékei:

  • AllServer=Minden tartomány csatlakozott a Windows Serverhez
  • AllComputer=Minden tartomány csatlakozott a Windows operációs rendszerű számítógéphez

Ha nincs megadva hatókör paraméter, a függvény a helyi számítógép Defender állapotát mutatja.

Csak egy Active Directory tartományra van szüksége, és ha Windows Defender információkat szeretne lekérni az ügyfélszámítógépekről, engedélyeznie kell a WinRm-et az összes kliens operációs rendszeren az itt leírtak szerint: Csoport Irányelvek: A WinRM engedélyezése Windows kliens operációs rendszerekhez (Windows 10, Windows 8, Windows 7).

A Get-AntiMalwareStatus függvény

A funkció használatához a PowerShell-munkamenetben folytassa a következő ponttal.


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
}

Hogyan kell használni

Másolja a fenti kódot a PowerShell ISE-be (ise.exe), és futtassa a kódot. Ezután írja be a parancsot, és szórakozzon vele.

Ha tartósan elérhetővé szeretné tenni a funkciót, hogy a funkció minden alkalommal elérhető legyen a PowerShell indításakor, létre kell hoznia egy mappát a C:\Program Files\WindowsPowerShell\Modules mappában. Nevezze el a mappát Get-AntiMalwareStatus. Ezután mentse a kódot .psm1 fájlként ebbe a mappába. Az alábbi képernyőkép segít.

Találkozunk legközelebb, újra a PowerShell-lel!

Kapcsolódó cikkek