Test Connection Troubles

In this week’s Prof. PowerShell column, I have an article on using the Test-Connection in Windows PowerShell. I thought it was pretty straightforward, but I didn’t take problems into account. I received an email asking what to do about error messages. For example, what if you have a computername in the list that can’t be resolved to an IP address? At first I thought you could use a traditional Trap, but after a little testing that’s not really going to give you what you want, I think. Here’s how I would handle it.

Now you can certainly use a Trap statement. You’ll need to use the –ErrorAction common parameter with Test-Connection cmdlet. That’s what I would do with most cmdlets. But in this case, I’m probably going to use it expecting a boolean value of True or False. The cmdlet is a wrapper for the Win32_PingStatus class and as such will attempt to resolve computernames.  You can use an IP address for the computername, but you’ll get the same type of error if the computer is down.

Instead, I’ll simply tell Test-Connection to ignore any exception and keep on rolling. I can (probaby) safely assume that if there was an exception that the computer is “down” or I do not have a valid connection, which is the whole point of the cmdlet anyway, right?

On my network some of these computers are valid and some are not. I don’t really care why a computer fails the connection test and I’m not sure I can get that information anyway from the underlying exception. The exception is the same, although the message does vary. Here’s almost the same code with the addition of a Trap statement.

The other significant change is that I changed the ErrorAction to Stop so that the exception is caught by the trap.  The Trap is part of the ForEach construct so that PowerShell will continue with the next command in the same scope as the trap.

Obviously there are many ways you can use Test-Connection and I won’t swear that these ideas will work in all situations, absolutely. But hopefully it will give you a place to start.

New Blog in development

I know I haven’t posted much this month.  I’m trying to get a new blog setup where I can offer more value and especially an easy way for you to download script and code samples.  In the mean time you can find me on “InterTubes” at Mr. Roboto, Prof. PowerShell and The Lonely AD Administrator. Or you can follow me on Twitter.

Thanks for sticking around.

Prof. PowerShell is taking roll

My weekly column that I’ve been writing for MCPMag.com is now officially Prof. PowerShell. The column’s goal is to introduce you to PowerShell and help you get up to speed. I obviously can’t teach you everything in a weekly 300 word column, but hopefully it will be enough to get you going and if nothing else, keep PowerShell on your radar. You’re going to have to eventually learn PowerShell so avoid the rush and start now. This week’s column introduces you to the Get-Member cmdlet.

You can also find PowerShell tips in some of last Windows Tip Sheet columns.

I hope you’ll let me know what you think. You can read Prof. PowerShell at http://mcpmag.com/columns/columnist.asp?columnistsid=81 or add the site’s RSS feed. I believe you can also get the column via weekly newsletter as well if you prefer.

If you want even more PowerShell goodness, I’d also suggest getting the Windows Administration in RealTime ejournal from RealTimePublishers.com. I write the Practical PowerShell column which solves a real-world problem with PowerShell. I think you’ll like it.

Technorati Tags: , , , MCPMag, Prof. PowerShell

PowerShell Blogging

Late last year I had moved my PowerShell blogging to PowerShellCommunity.org.  However, decisions have been made to discontinue the blog module.  Now, all my PowerShell related blogging will be back at blog.sapien.com. Hopefully you already have it in your RSS feed. You can click on the Powershell category to see all related posts from not only me but also Don Jones.

On a related note, keep an eye on my Windows Tip Sheet column. You should start seeing more and more PowerShell in the next few weeks.

Technorati Tags: , , , PowerShellCommunity

Prof. PowerShell

As many of you know, I write the popular Mr. Roboto column for REDMOND magazine. Starting in January, I will be taking on a new title, Professor PowerShell. The weekly Windows Tip Sheet column I’ve been doing for MCPMag.com will be come Prof. PowerShell. The column will still be weekly, but will focus entirely on PowerShell. My goal is to provide a little education as well as examples of how to use PowerShell to solve real-world problems.

The column is sent out weekly as a newsletter.  Current Tip Sheet subscribers will automatically get the new column. If you’d like to get the newsletter as well, subscribe now to the MCPMag.com newsletter.  Go to http://mcpmag.com/, click Get Newsletters and subscribe to MCPMag.com News.  In addition to my column you’ll gets lots of other useful information.  Or setup your RSS reader to subscribe to the column’s feed.

Technorati Tags: ,