Remotely reboot computer twice

倾然丶 夕夏残阳落幕 提交于 2019-12-13 19:10:01

问题


I have a scenario where I need to reboot a computer twice, remotely. My command:

Invoke-Command -ComputerName $computerName -Credential $cred -ScriptBlock {
     workflow Reboot {
        Restart-Computer -Wait
        Restart-Computer -Wait
      }
       Reboot
  }

But this returns the error

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

回答1:


You can't use -Wait if you are restarting the local computer (which you are doing with the remote session).

Documentation for Restart-Computer states:

The Wait parameter is not valid when you are restarting the local computer. If the value of the ComputerName parameter contains the names of remote computers and the local computer, Restart-Computer generates a non-terminating error for Wait on the local computer, but it waits for the remote computers to restart.

You will need to change your command so it does not use Invoke-Command:

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


来源:https://stackoverflow.com/questions/53389934/remotely-reboot-computer-twice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!