我写了一个PowerShell脚本来捕获McAfee AVDate,并且它也提供输出。但问题是,我在脚本中添加了另一行,如果McAfee AVDate日期比当前日期早2天,则应该以红色显示McAfee AVdate,但这不起作用。PowerShell脚本查询
任何人都可以帮我解决这个问题吗?
$AVDate = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Wow6432Node\McAfee\AVEngine").AVDatDate
$AVDatDate = $AVDate
$thedate = get-date -date $(get-date).adddays(-2) -format yyyy-MM-dd
if($AVDatDate -lt $thedate) {
Add-Content $report "<tr>"
Add-Content $report "<td bgcolor= 'White' height='30' align=center><B>12</B></td>"
Add-Content $report "<td bgcolor= 'White' height='30' align=left><B>McAfee AVDate</B></td>"
Add-Content $report "<td bgcolor= 'red' height='30' align=left><B>$AVDatDate</B></td>"
Add-Content $report "</tr>"
}
else
{
Add-Content $report "<tr>"
Add-Content $report "<td bgcolor= 'White' height='30' align=center><B>12</B></td>"
Add-Content $report "<td bgcolor= 'White' height='30' align=left><B>McAfee AVDate</B></td>"
Add-Content $report "<td bgcolor= 'Aquamarine' height='30' align=left><B>$AVDatDate</B></td>"
Add-Content $report "</tr>"
}
因为它永远不会去else块。您必须检查来自$ avdate的日期,并相应地输入条件 –
日期即将采用此格式“McAfee AVDate \t 2017/06/21”,但颜色不会变为红色。由于日期比当前日期早了9天 – Sandeep
因此您明确提及elseif中的条件 –