用于重启计算机的 Powershell 工作流程

标签 powershell

代码:

workflow Test-RemoteReboot{
    param ([string[]]$serverNames)
    foreach -parallel($server in $serverNames){
        Restart-Computer -PSComputerName $server -Wait -Force
    }
}

Test-RemoteReboot SP,SP2

问题: 这是我在 powershell 中构建的一个相当长的工作流程的一小段摘录。从各方面来看,这应该可行,但我收到以下错误(即使在单独运行此脚本时):

Microsoft.PowerShell.Utility\Write-Error : The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: The computer SP2 is skipped. Fail to retrieve its LastBootUpTime via the WMI service with the following error message: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA). At line:433 char:25 + ... Receive-Job -Job $job -Wait -Verbose -Debug -ErrorAction ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], ActionPreferenceStopException + FullyQualifiedErrorId : System.Management.Automation.ActionPreferenceStopException,Microsoft.PowerShell.Commands.WriteErrorCommand + PSComputerName : [localhost]

我调查了 RPC 服务器不可用的问题。防火墙关闭,RPC 服务正在运行,服务器在域中,工作流从域成员计算机运行,作为域管理员。我可以成功地通过 PSRemote 进入机器并执行任何操作。我什至可以这样做:

workflow Test-LocalRebootRemotely{
param ([string[]]$serverNames)
    foreach -parallel($server in $serverNames){
        InlineScript { Restart-Computer -Force } -PSComputerName $server
    }
}

Test-LocalRebootRemotely SP,SP2

问题是,我需要一个返回值来确定我是否需要重新启动并处理远程计算机之外的其他逻辑。我确实注意到在它出错之前有一个异常的暂停。所以也许这是超时?有人有类似的问题吗?

最佳答案

您可以使用 -Protocol WSMan 参数尝试 Restart-Computer cmdlet,而不是默认的 DCOM over RPC 协议(protocol)(-Protocol DCOM ).

这将确认您的 RPC 网络数据包在某处被阻止。

关于用于重启计算机的 Powershell 工作流程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42959938/

相关文章:

sql - SQLCMD, 'tee'无法识别为内部或外部命令

powershell - PowerShell 获取服务问题

c++ - 构建 Qt-Static 5.3.2 时遇到问题

powershell v2.0 从批处理 cmd 文件传递​​变量计算机名参数

powershell - 从Powershell启动Elevated CMD.exe

powershell - 我可以在 PowerShell 'string' 中使用单引号吗?

azure - 如何使用 Powershell 更新 Azure 资源模板部署的参数

powershell - Azure 9.1 上的 Get-AzureVMDscExtensionStatus 返回 404 blob 错误

sql - SQL 查询返回什么到 PowerShell 变量中?

powershell - 从函数返回的整数不与 -eq 运算符一起使用