如题,今天收到个这样的需求。也是无语。写个脚本做个记录
# 过滤电脑
$computers = Get-ADComputer -Filter {Name -like "cndw*"}
# 执行循环
foreach ($computer in $computers){
# 检测注册表值
$registryPath = Invoke-Command -ComputerName $computer.Name -ScriptBlock {Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update"}
$rebootRequiredEntry = "RebootRequired"
# 设置记录文件
$logFilePath = "%SystemDrive%\%UserName%\Desktop\waitreboot.txt"
$logfailPath = "%SystemDrive%\%UserName%\Desktop\waitrebootfail.txt"
# 判断条目是否存在
if (Test-Path -Path "$registryPath\$rebootRequiredEntry")
{
{
Write-Output "$computer,The RebootRequired entry exists"
Out-File -FilePath $logFilePath -Append -NoClobber
} else {
Write-Output "$computer,The RebootRequired entry does not exist."
Out-File -FilePath $logfailPath -Append -NoClobber
}
}
好了,就这样吧。
后来发现这种执行超级慢,很多电脑不在线。如果你要实地使用,还请做个在线判断。