Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Trapping Get-WmiObject:The RPC server is unavailable.

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 11-09-2006   #1 (permalink)
Burtamus
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 SpecsSystem Spec
Old 11-09-2006   #2 (permalink)
Marcel J. Ortiz [MSFT]
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 SpecsSystem Spec
Old 11-10-2006   #3 (permalink)
Roman Kuzmin
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 SpecsSystem Spec
Old 11-10-2006   #4 (permalink)
Flowering Weeds
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 SpecsSystem Spec
Old 11-10-2006   #5 (permalink)
Adam Milazzo
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 SpecsSystem Spec
Closed Thread

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


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51