所以我创建了一个每周重启脚本。我阅读了一个 AD 组,然后在周末重新启动了一堆计算机。然后,我通过电子邮件发送带有日志的 HTML 结果。我通过在列表中添加几台停机计算机来测试这一点。它只返回最后一台无法ping 通的计算机。有人能告诉我为什么吗?我需要第二双眼睛。我以前做过这种类型的哈希表,它工作得很好。
$RBList = (Get-QADGroupMember prv_RebootSchedule | Sort Name | Select -expand Name)
foreach($PC in $RBList){
$datetime = Get-Date
ping -n 2 $PC >$null
if($lastexitcode -eq 0){
shutdown /r /f /m \\$PC /d p:1:1 /t 600 /c "Weekly Reboot - Maintnence scheduled!"
write-host "$pc is rebooting"
$result = "Success"
} else {
Write-host "$pc has error adding to table"
$Result = "Error - Check"
}
$table = [ordered]@{
Workstation = $pc
Result = $result
Time = $datetime
}
}
$html = [PSCustomObject]$table | convertto-html -CssUri "C:\scripts\automatedreboot\table.css"
send-mailmessage -to "email@email.com" -from "Automated Reboot<no-reply@email.com>" -subject "Automated Reboot Error Log" -BodyAsHtml "$html" -smtpserver smtp.email.com