header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Error Checking in script dealing with network computers
Last Post 25 May 2008 03:32 PM by TimParker. 3 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
TimParkerUser is Offline
New Member
New Member
Posts:4

--
25 May 2008 10:29 AM  

I have a question that I would like to get some feedback on. I am working on a script to pull some WMI data about all the computers on my network (only about 50-60 - small non-profit agency that I work for). I have the script working after getting a bit of help from the Usenet group. But now am finding some "issues" (and I use that term loosely) with our AD structure and how the Objects are organized. But thats another whole issue.

The question is what is the best way for "skipping over" computers that may be listed in an AD group but are OFFLINE (off the network). I was given the suggestion of the '-errorAction silentlyContinue' of gwmi which seemed to get me a bit farther but the script seems to still error out.

I am using get-QADcomputer to get the list and then passing it into gwmi and then selecting my fields that I need from the WMI Object. Eventually I will output this for my use through either an email or a file on the network to view.

 

Thanks.

Tim Parker

 

 

DonJUser is Offline
PowerShell MVP
Basic Member
Basic Member
Posts:134

--
25 May 2008 02:52 PM  
You've really only got a couple of choices. You could ping the computer first - assuming your computers are normally pingable, that'll tell you if it's on the network or not and is a pretty quick test. But it won't tell you if WMI is working and available; for that, you simply have to wait for WMI to time out and perhaps trap the error.

Adding -EA "SilentlyContinue" will suppress any errors from GWMI. However, you've got to immediately check, on the next line of code, to see if GWMI worked or not. E.g.,....

$wmi = gwmi win32_service -comp $name -ea SilentlyContinue

Anything in your script which attempts to use $wmi would error if GWMI failed. So you might do this:

$wmi = $null
$wmi = gwmi win32_service -comp $name -ea SilentlyContinue
if ($wmi -eq $null) {
# didn't work
} else {
# did work
}

But you do still have to wait for WMI to time out, that way.
halr9000User is Offline
Basic Member
Basic Member
Posts:303

--
25 May 2008 02:55 PM  
I wrote a script and a blog post on this topic, you can find it here: http://halr9000.com/article/447

The end result would look like this:

get-content srvlist.txt | select-alive | get-wmiobject win32_blah
TimParkerUser is Offline
New Member
New Member
Posts:4

--
25 May 2008 03:32 PM  
Thanks to both of you, I will take at Don's suggestions and look at the script from Hal. Appreciate the help!
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer