远程重启电脑两次 [英] Remotely reboot computer twice

查看:116
本文介绍了远程重启电脑两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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
  }

但这会返回错误

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.

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

重启计算机 状态:

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

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.

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

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

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

这篇关于远程重启电脑两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆