【发布时间】:2020-12-31 12:56:24
【问题描述】:
我正在运行以下代码,但重启不起作用。我的意图是一次在所有远程机器上并行运行重启命令。
$YourFile = gc "machinelst.txt"
$username = "user1"
$password = "pass1"
$secpw = ConvertTo-SecureString $password -AsPlainText -Force
$cred = New-Object Management.Automation.PSCredential ($username, $secpw)
foreach ($computer in $YourFile)
{
Invoke-Command -ComputerName $computer -credential $cred -ErrorAction Stop -ScriptBlock { Restart-Computer -ComputerName $computer -Force } -AsJob
}
【问题讨论】:
-
删除 -ErrorAction Stop 读取错误
-
感谢您的回复,我已删除 -ErrorAction Stop 并再次运行脚本。它没有重新启动
-
你的错误文本是什么
-
Id 名称 PSJobTypeName 状态 HasMoreData 位置命令 -- ---- ------------- ----- ------------ -------- ------- 76 Job76 RemoteJob 失败 False RemoteHost1 Restart-Computer -Com... 78 Job78 RemoteJob 失败 False RemoteHost2 Restart-Computer -Com... 80 Job80 RemoteJob 失败 False RemoteHost3 Restart -Computer -Com...这是输出
-
删除 -AsJob 并告诉我你的错误
标签: powershell powershell-2.0 powershell-3.0 powershell-4.0