【发布时间】:2016-07-11 21:36:08
【问题描述】:
我只是一个基本的,我是 Powershell 的新手。试图让下面的语句起作用。
$date = (Get-Date).AddDays(-1)
$currentdate = Get-Date -Format d
$check = Get-WinEvent -FilterHashtable @{LogName="CloudBackup";StartTime=$date;ID=3} *>$null
if ($check -eq $true) {
Write-Host "`nOK: Azure Backup was successful on $currentdate"
exit 0
} else {
Write-Host "`nCritical: Problem with Azure Backup - $currentdate"
exit 2
}
特别是if ($check -eq $true) 似乎没有达到预期的效果。由于$check 在事件日志中检查事件ID 3,如果它在那里,它应该返回true,如果不是false。不幸的是,它每次都只返回 false。
有人可以建议吗?有没有更好的方法来做到这一点?
【问题讨论】:
标签: powershell event-log