【问题标题】:Error handling 0x800706BA - RPC-Server not found错误处理 0x800706BA - RPC-Server 未找到
【发布时间】:2019-01-02 12:51:43
【问题描述】:

我编写了一个脚本来从服务器列表中获取 OSVersion。某些服务器不响应“Get-WmiObject”命令。
我想要一个发生此错误的所有主机名的列表。

这为我提供了出现此错误的前几台服务器的列表。
当第一个服务器响应没有错误时,脚本停止。

我希望脚本在服务器未发送错误时不执行任何操作并继续。

有人知道如何解决这个问题。

提前致谢。

我尝试设置“-ErrorAction continue”,但整个脚本没有运行。

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force
$arraylist_OSInfo = New-Object System.Collections.ArrayList
$file=Get-Content -Path "C:\Temp\PS-Skripte\server2.txt"
foreach ($Hostname in $file)
 {
    try
    {
        Get-WmiObject Win32_OperatingSystem -ComputerName $Hostname -ErrorAction Stop
    }

    catch [Exception]
    {
        if ($_.Exception.GetType().Name -eq "COMException")
        {
          echo "$Hostname - RPC Error" | Out-File -FilePath "C:\temp\PS-Skripte\RPCerror.log" -Append -encoding unicode  
        }
    }
}

我希望从所有发送错误的服务器中获取主机名列表:

"Get-WmiObject : Der RPC-Server ist nicht verfügbar. (Ausnahme von HRESULT: 0x800706BA)"

作为 cmdlet“Get-WmiObject”的答案

【问题讨论】:

    标签: powershell exception rpc


    【解决方案1】:

    我稍微修改了你的代码

    $hostnames = 'NoSuchmachine', 'DoesNotExist'
    
    foreach ($hostname in $hostnames){
    
    try {
      Get-WmiObject -Class win32_operatingsystem  -ComputerName $hostname  -ErrorAction Stop
    }
    catch {
    
    if ($_.Exception.GetType().Name -eq "COMException") {
       out-file -FilePath c:\test\rpcError.txt -InputObject "$hostname - RPC Error" -Append -Encoding unicode
    
    }
    }
    
    }
    

    文件内容为

    NoSuchmachine - RPC Error
    DoesNotExist - RPC Error
    

    我认为你想要什么。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 2021-06-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多