0

我已安装 Az.Security 模块来运行 Get-AzSecurityAlerts 命令,该命令提供 Azure 安全中心中所有安全警报的详细信息。运行此命令后,我收到所有警报,但

我只需要在特定日期之前、之后或之后发出警报。但我无法修改参数ReportedTimeUtc

请帮助我以以下格式修改此参数以获得所需的结果。

Get-AzSecurityAlerts | Where-Object {$_.ReportedTimeUtc -gt '22-Jun-19 6:16:20 PM' -or -eq '23-Jun-19 8:00:00 PM'}
4

2 回答 2

1

一般来说,在 powershell 中,这是您在多个条件下进行过滤的方式:

Get-AzSecurityAlerts | Where-Object {
    $_.ReportedTimeUtc -gt '22-Jun-19 6:16:20 PM' -or
    $_.ReportedTimeUtc -eq '23-Jun-19 8:00:00 PM' -or xxx}
于 2019-09-14T07:14:16.987 回答
1

评论中的这种命令格式应该可以工作,对我来说可以正常工作。

Get-AzSecurityAlert | Where-Object {$_.ReportedTimeUtc -gt ([DateTime]'7-5-2019 10:00:20 AM')}

我使用(Get-AzSecurityAlert | Where-Object {$_.ReportedTimeUtc -gt ([DateTime]'7-5-2019 10:00:20 AM')}).ReportedTimeUtc来检查ReportedTimeUtc结果中每个警报的时间是否正确。

在此处输入图像描述

-le参数也有效,

Get-AzSecurityAlert | Where-Object {$_.ReportedTimeUtc -le ([DateTime]'7-5-2019 10:00:20 AM')}

我们还可以获取时间范围之间的警报。

Get-AzSecurityAlert | Where-Object {$_.ReportedTimeUtc -gt ([DateTime]'7-5-2019 10:00:20 AM') -and $_.ReportedTimeUtc -le ([DateTime]'7-6-2019 10:00:20 AM')}

使用时-eq,它不返回任何结果。不知道为什么它不起作用,我的解决方法是使用如下所示的小时间范围,它会在7-5-2019 10:00:20 AM.

Get-AzSecurityAlert | Where-Object {$_.ReportedTimeUtc -gt ([DateTime]'7-5-2019 10:00:19 AM') -and $_.ReportedTimeUtc -le ([DateTime]'7-5-2019 10:00:21 AM')}

检查(Get-AzSecurityAlert | Where-Object {$_.ReportedTimeUtc -gt ([DateTime]'7-5-2019 10:00:19 AM') -and $_.ReportedTimeUtc -le ([DateTime]'7-5-2019 10:00:21 AM')}).ReportedTimeUtc,它工作正常。

在此处输入图像描述

于 2019-09-16T07:05:49.623 回答