jeudi 9 mai 2019

If statement in powershell dependant on if RPC Server is unavailable

I'm writing a script in PowerShell that ideally would gather information from another server. If it's not able to reach that server, I want to prompt it to have the user manually enter the information. I know how to do all of these, but I'm getting hung up when the RPC Server is unavailable. I will also say that I know how to fix the error when it occurs, but I do not want to rely on my end users to have to go in and fix this. As an example, if I run:

get-wmiobject Win32_ComputerSystem -Computer 10.5.21.94

the result I get back is:

get-wmiobject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At line:1 char:1
+ get-wmiobject Win32_ComputerSystem -Computer 10.5.21.94
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], 
COMException
+ FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

I'm trying to find a way to write an if statement that will check to see if the RPC server is available or not, but I'm not sure what to check in order to create a true/false variable. And again, I'm not really looking for someone to tell me how to write the if statement, I'm just trying to figure out any query I can run to determine if I can properly connect to this server and get a result back that can tell me to continue on or not.

Aucun commentaire:

Enregistrer un commentaire