PowerShell: Etki Alanına Katılan Tüm Bilgisayarlardan Windows Defender Durumunu Alma (Get-AntiMalwareStatus)
Windows 10 ve Windows Server 2016 veya üstünü mü kullanıyorsunuz? Tüm bilgisayarlardan Windows Defender Kötü Amaçlı Yazılımdan Koruma'nın durumunu kontrol etmek mi istiyorsunuz? O halde doğru yere geldiniz. Size bunu yapmanız için bir araç vereceğim.
Amaç
Çok fazla konuşmaya gerek yok, Get-AntiMalwareStatus adı verilen gelişmiş bir PowerShell işleviyle neler mümkün olabilir.
Get-AntiMalwareStatus -Scope AllServer | Format-Table -AutoSize
Harika, değil mi?
Format Tablosu olmadan çıktı liste formatında görüntülenir. Etki alanına katılan tüm bilgisayarlardan kötü amaçlı yazılım durumunu almanın bir örneğini burada bulabilirsiniz.
Kapsam parametresi için olası değerler şunlardır:
- AllServer=Tüm alan adı Windows Server'a katıldı
- AllComputer=Tüm etki alanına katılan Windows işletim sistemli bilgisayar
Herhangi bir kapsam parametresi verilmezse işlev, yerel bilgisayarın Defender durumunu gösterir.
İhtiyacınız olan tek şey bir Active Directory etki alanıdır ve istemci bilgisayarlardan Windows Defender bilgilerini almak istiyorsanız, burada açıklandığı gibi tüm istemci işletim sistemlerinde WinRm'yi etkinleştirmeniz gerekir: Grup İlkeler: Windows İstemci İşletim Sistemleri için WinRM'yi Etkinleştirme (Windows 10, Windows 8, Windows 7).
Get-AntiMalwareStatus işlevi
Bu işlevi PowerShell oturumunuzda kullanmak için bir sonraki noktaya geçin.
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
}
Bu nasıl kullanılır
Yukarıdaki kodu PowerShell ISE'ye (ise.exe) kopyalayın ve kodu çalıştırın. Daha sonra komutu yazın ve onunla eğlenin.
İşlevin kalıcı olarak kullanılabilir olmasını istiyorsanız ve böylece PowerShell'i her başlattığınızda işlevin kullanılabilir olmasını istiyorsanız C:\Program Files\WindowsPowerShell\Modules konumunda bir klasör oluşturmanız gerekir. Klasöre Get-AntiMalwareStatus adını verin. Daha sonra kodu bu klasöre .psm1 dosyası olarak kaydedin. Aşağıdaki ekran görüntüsü size yardımcı olacaktır.
Bir dahaki sefere PowerShell ile tekrar görüşmek üzere!



