当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] PowerShell:从所有加入域的计算机获取 Windows Defender 状态 (Get-AntiMalwareStatus)

作者:精品下载站 日期:2024-12-14 20:37:50 浏览:12 分类:玩电脑

PowerShell:从所有加入域的计算机获取 Windows Defender 状态 (Get-AntiMalwareStatus)


您使用的是 Windows 10 和 Windows Server 2016 或更高版本?想要检查所有计算机上 Windows Defender 反恶意软件的状态吗?那么您就来对地方了。我会给你一个工具来做到这一点。

目标

无需多言,以下是名为 Get-AntiMalwareStatus 的高级 PowerShell 函数的功能。


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

[玩转系统] PowerShell:从所有加入域的计算机获取 Windows Defender 状态 (Get-AntiMalwareStatus)

很酷,哈?

如果没有 Format-Table,输出将以列表格式显示。以下是从所有加入域的计算机获取恶意软件状态的示例。

[玩转系统] PowerShell:从所有加入域的计算机获取 Windows Defender 状态 (Get-AntiMalwareStatus)

范围参数的可能值为:

  • AllServer=所有加入域的 Windows Server
  • 所有计算机=所有加入域的 Windows 操作系统计算机

如果未给出范围参数,该函数将显示本地计算机的 Defender 状态。

[玩转系统] PowerShell:从所有加入域的计算机获取 Windows Defender 状态 (Get-AntiMalwareStatus)

您所需要的只是一个 Active Directory 域,如果您想从客户端计算机检索 Windows Defender 信息,则必须在所有客户端操作系统上启用 WinRm,如下所述:策略:为 Windows 客户端操作系统(Windows 10、Windows 8、Windows 7)启用 WinRM。

函数 Get-AntiMalwareStatus

要在 PowerShell 会话中使用此函数,请转到下一点。


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://a-d.site 

[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
}

如何使用它

将上述代码复制到 PowerShell ISE (ise.exe) 中并运行该代码。然后输入命令并享受它的乐趣。

如果您想让该函数永久可用,以便每次启动 PowerShell 时该函数都可用,则必须在 C:\Program Files\WindowsPowerShell\Modules 中创建一个文件夹。将文件夹命名为 Get-AntiMalwareStatus。然后将代码另存为该文件夹中的 .psm1 文件。下面的屏幕截图将为您提供帮助。

[玩转系统] PowerShell:从所有加入域的计算机获取 Windows Defender 状态 (Get-AntiMalwareStatus)

下次再见,再次使用 PowerShell!

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯