我正在尝试创建一个PowerShell脚本来获取1或2天之前的失败修补程序。
所以我试图使用where-object选择2天失败的补丁,但是没有正确地输出正确的输出。
以下是我在谷歌帮助下编写的命令。
$mail_body = Get-WmiObject -Class win32_reliabilityRecords -Filter "SourceName = 'Microsoft-Windows-WindowsUpdateClient'" | Select-Object user, productname, @{LABEL = “date”;EXPRESSION = {$_.ConvertToDateTime($_.timegenerated)}} | where { $_.message -match ‘failure’ } | ConvertTo-Html -Head $style
答案 0 :(得分:0)
这应该检索过去7天内发生的事件:
Get-WmiObject -Class Win32_ReliabilityRecords -Filter "SourceName = 'Microsoft-Windows-WindowsUpdateClient'" |
Select-Object { LABEL = "date"; EXPRESSION = { $_.ConvertToDateTime($_.timegenerated) } } |
Where-Object { $_.date -ge ([datetime]::today).AddDays(-7) }