Powershell 远程重新启动计算机两次

Powershell 远程重新启动计算机两次,powershell,remote-access,invoke-command,Powershell,Remote Access,Invoke Command,我有一个场景,我需要远程重启计算机两次。 我的命令: Invoke-Command -ComputerName $computerName -Credential $cred -ScriptBlock { workflow Reboot { Restart-Computer -Wait Restart-Computer -Wait } Reboot } 但这会返回错误 Failed to restart the compu

我有一个场景,我需要远程重启计算机两次。 我的命令:

Invoke-Command -ComputerName $computerName -Credential $cred -ScriptBlock {
     workflow Reboot {
        Restart-Computer -Wait
        Restart-Computer -Wait
      }
       Reboot
  }
但这会返回错误

Failed to restart the computer com1 with the following error message: A system shutdown is in progress.
    + CategoryInfo          : OperationStopped: (com1:String) [Restart-Computer], InvalidOperationException
    + FullyQualifiedErrorId : RestartcomputerFailed,Microsoft.PowerShell.Commands.RestartComputerCommand
    + PSComputerName        : com1

如果要重新启动本地计算机(您正在使用远程会话执行此操作),则不能使用
-Wait

各国的文件:

重新启动本地计算机时,等待参数无效。如果ComputerName参数的值包含远程计算机和本地计算机的名称,重新启动计算机会为本地计算机上的等待生成非终止错误,但它会等待远程计算机重新启动

您需要更改命令,使其不使用Invoke命令:

Restart-Computer -ComputerName $computerName -Credential $cred -Wait