![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Trapping Get-WmiObject:The RPC server is unavailable. Some assistance is required. I'm trying to find out what versions of Windows Server we have installed on the network. I've got about everything working except the trapping. I've tried VBScript and now PowerShell. The On Error did not trap this error, and neither is the TRAP command. Here is a bit of the code: if (Ping -w $timeout $strComputer|find "Request timed out.") { write-host "UnPingable Computer" } else { write-host "Ping Successful" trap { write-host "Non-Windows OS"; break } $colItems = get-wmiobject -class "Win32_OperatingSystem" -namespace "root\CIMV2" -computername $strComputer foreach ($objItem in $colItems) { $strComputerName = $objItem.CSName $strComputerCaption = $objItem.Caption $strComputerVersion = $objItem.CSDVersion $strComputerDescription = $objItem.Description } When the code hits a non-windows server, I get: Ping Successful Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x80070 6BA) At c:\scripts\Computer.ps1:27 char:29 + $colItems = get-wmiobject <<<< -class "Win32_OperatingSystem" -n amespace "root\CIMV2" -computername $strComputer I want it to fail, write "Non-Windows OS' and move on to the next computer in the array. Any help would be appreciated. -- TIA, Burt =============================== There's nothing so permanent as a temporary solution - Me. =============================== |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Trapping Get-WmiObject:The RPC server is unavailable. get-wmiobject is writing an error object. I would probably use the error variable parameter for something like this. $obj = get-wmiobject -comp foobar win32_operatingsystem -ev myError -ea SilentlyContinue if ($myError -ne $null) { # We got an error and its stored in $myError. Do whatever you want here. } else { # Everything went as planned, $obj should have the wmi object. } I'm pretty sure somebody wrote a blog post explaining errors, error object, exceptions, etc, however I can't find it right now. - Marcel "Burtamus" <burtamus2003@REMOVETHISyahoo.com> wrote in message news:%23YVC9tCBHHA.4292@TK2MSFTNGP02.phx.gbl... > Some assistance is required. I'm trying to find out what versions of > Windows Server we have installed on the network. I've got about everything > working except the trapping. I've tried VBScript and now PowerShell. The > On Error did not trap this error, and neither is the TRAP command. > > Here is a bit of the code: > > if (Ping -w $timeout $strComputer|find "Request timed out.") > { > write-host "UnPingable Computer" > } > else > { > write-host "Ping Successful" > trap { write-host "Non-Windows OS"; break } > > $colItems = get-wmiobject -class "Win32_OperatingSystem" -namespace > > "root\CIMV2" -computername $strComputer > foreach ($objItem in $colItems) { > > $strComputerName = $objItem.CSName > $strComputerCaption = $objItem.Caption > $strComputerVersion = $objItem.CSDVersion > $strComputerDescription = $objItem.Description > } > > When the code hits a non-windows server, I get: > Ping Successful > Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: > 0x80070 > 6BA) > At c:\scripts\Computer.ps1:27 char:29 > + $colItems = get-wmiobject <<<< -class > "Win32_OperatingSystem" -n > amespace "root\CIMV2" -computername $strComputer > > I want it to fail, write "Non-Windows OS' and move on to the next computer > in the array. Any help would be appreciated. > -- > TIA, Burt > =============================== > There's nothing so permanent as > a temporary solution - Me. > =============================== > > |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: Trapping Get-WmiObject:The RPC server is unavailable. "Marcel J. Ortiz [MSFT]" <mosoto@online.microsoft.com> wrote in message > I'm pretty sure somebody wrote a blog post explaining errors, error > object, exceptions, etc, however I can't find it right now. I wonder if it is really so and I am very keen to look at it. PowerShell documentation and help are almost (or completely?) silent. BTW, looking at hundreds of scripts here and there I am coming into conclusion that many people just abstain of using trap mechanism at all. Am I wrong? -- Thanks, Roman |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: Trapping Get-WmiObject:The RPC server is unavailable. "Roman Kuzmin" > BTW, looking at hundreds of scripts > here and there I am coming into > conclusion that many people just abstain > of using trap mechanism at all. Am I wrong? > Been this way since scripting started. ![]() What you are really seeing (hopefully) are just "demo" scripts! One's that make a quick point. Trapping just adds to the examples - unneeded demo lines! But then again very few use the newer C / C++ compiler's Safe C / C++ Libraries (in demo code either) or real production code (based on scanning open source code)! ![]() |
My System Specs![]() |
| | #5 (permalink) |
| Guest | Re: Trapping Get-WmiObject:The RPC server is unavailable. Roman Kuzmin wrote: > "Marcel J. Ortiz [MSFT]" <mosoto@online.microsoft.com> wrote in message >> I'm pretty sure somebody wrote a blog post explaining errors, error >> object, exceptions, etc, however I can't find it right now. > > I wonder if it is really so and I am very keen to look at it. PowerShell > documentation and help are almost (or completely?) silent. There is this: http://blogs.msdn.com/powershell/arc...rvariable.aspx > BTW, looking at hundreds of scripts here and there I am coming into > conclusion that many people just abstain of using trap mechanism at all. Am > I wrong? I hope nobody uses it! Then Microsoft will be able to fix its broken scoping in the next release without fear of breaking backwards compatibility. :-) |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| The RPC server is unavailable | ma-soares | PowerShell | 3 | 02-14-2008 10:32 AM |
| RPC Server is unavailable | Paul | Vista networking & sharing | 2 | 01-28-2008 07:05 PM |
| RPC Server is unavailable | Paul | Vista General | 4 | 01-27-2008 06:57 PM |
| Shared Fax server unavailable | Marcus | Vista print fax & scan | 9 | 08-14-2007 03:36 AM |
| The RPC server is unavailable. | churin | Vista General | 4 | 03-22-2007 07:42 AM |