【问题标题】:Remotely reboot computer twice远程重启电脑两次
【发布时间】:2018-11-20 09:30:07
【问题描述】:

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

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

【问题讨论】:

    标签: powershell remote-access invoke-command


    【解决方案1】:

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

    Restart-Computer 的文档说明:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-25
      • 1970-01-01
      • 1970-01-01
      • 2022-01-02
      • 2018-07-21
      • 1970-01-01
      相关资源
      最近更新 更多