Error handling 0x800706BA - RPC-Server not found

0

I have written a script to get the OSVersion from a List of Servers. Some Servers don´t respond to the "Get-WmiObject" command.
I want a list of all Hostnames where this error occurs.

This gives me an list of the first few Servers with this error.
When the first Server is responding with no error, the script stops.

I want the script to do nothing and continue when a Server isn´t sending an error.

Has anybody an idea how to solve this problem.

Thanks in advance.

I tried to set "-ErrorAction continue" but then the whole script doesn´t run.

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  
        }
    }
}

I expect to get a list of hostnames from all server who are sending the Error:

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

as answer of the cmdlet "Get-WmiObject"

powershell
exception
rpc
asked on Stack Overflow Jan 2, 2019 by Thomas Lang • edited Jan 2, 2019 by Theo

1 Answer

0

I've modified your code slightly

$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

}
}

}

The contents of the file are

NoSuchmachine - RPC Error
DoesNotExist - RPC Error

Which is what you want I think.

answered on Stack Overflow Jan 2, 2019 by Richard Siddaway

User contributions licensed under CC BY-SA 3.0