The other PowerShell lessons I learned from Don Jones at the Deep Dive

Hello everyone,

Ed and I arrived in SC Wed night late and I have been catching up on housework, errands and email. Finally I am at the keyboard to share with you the other 2 lessons I learned at the PowerShell Deep Dive Pre con session with Don Jones.

The first one is do not use Write-Host in a script you wish to keep. Now for you beginner scripters like me you may not know why. Write-host places the output on your screen and that is it. Once you have sent the output to the script, you cannot use it for anything else. It is like sending something to the printer. Once I have sent something to the printer, I cannot rearrange the stuff on the page. That is the same thing with writing to the screen. Once you have used Write-Host you are done.

Ok, so what are the options for dealing with output? Well for one thing, you can simply place your output in a string. When you do that, you still have a string object, and you can later send that to a format-list or a format-table. The best thing is to return an object. To create an output object, use the New-Object PsObject command, and add your information as properties to that object. It is a little confusing, and I am certianly am not going to attempt it here without someone like the Scripting Guy or Don Jones looking over my shoulder to make sure I get it right. But check the Hey Scripting Guy blog for details. Interestingly enough, this seems to be a major theme with the judges during this years 2011 Scripting Games. I have seen this comment over and over again from the judges — and not just only on my 10 entries either.

The last thing I learned is the fact that you do not always have to use the line continuation character if you code is too long for one physical line. If you code the lines correctly then there is no need to manually insert the line continuation. For example if you open a curly bracket, “{” then PowerShell knows you have to have a closing curly bracket “}” to complete the command.  I am not going into great detail on this because teaching is not my role in life. My role is to share information and resources, be supportative and encouraging to other beginner scripters and  to help Ed stay organized.  With that said you can find Don on this webpage.

Again thank you Don for a wonderful pre-con and some marvelous conversations. Looking forward to seeing you at TechEd in Atlanta in less than a month. Maybe I can get Don’s autograph on my copy of his new book…..I hope so.

Hope to see lots of you at TechEd and good luck to all in the 2011 Scripting Games as Ed and the other judges wrap up the judging this weekend.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: