我想在工作场所关闭几乎所有的个人电脑(如果它们运行超过2天) 我已经在上一周和本周的脚本上工作并试图摆脱错误办法。远程关闭多台PC
$days = -0
$date = (get-date).adddays($days)
$lastboot = (Get-WmiObject Win32_OperatingSystem).LastBootUpTime
$Computer = Get-ADComputer -SearchBase 'OU=______,OU=______,DC=______,DC=______' ` -Filter '*' | Select -EXP Name
$lastbootconverted = ([WMI]'').ConvertToDateTime($lastboot)
write-host $date
write-host $lastboot
write-host $lastbootconverted
if($date -gt $lastbootconverted)
{
write-host Need to reboot
(Stop-Computer -$Computer -Force)
}
else
{
write-host no need to reboot
}
当我运行它,它说 的“RPC-服务器不可用(例外HRESULT:0x800706BA)。” 但如果我只是把代替“$电脑”一台PC的名称,它关闭个人电脑像我想要的。什么是RPC服务器错误?我没有防火墙的启动,所以我无言以对......
的OU = _____和DC = ______是私人公司名称
你 - $计算机应该是没有$计算机 –
@Taylor吉布我不这么认为,但我尝试过了,它并没有改变。 – Gunter
$电脑的输出是什么? – BenH