Cold. My nose is cold. My left eye opens slowly to investigate. Everything is dark. Cold and dark.

"So why am I awake," I wonder seemingly to myself.

No answers are forthcoming. So my right eye slowly opens to bring a modicum of assistance to the ongoing investigation. Still no answers present themselves. Where am I? What country am I in?

"Cold. Spartan furnishings. Guten Morgen! Ich bin in Deutschland! Ja! Das OktoberFest!" he thinks.

The Scripting Guy springs from his bed in anticipation. Mas Beir. Gros bretzel. OktoberFest! He rounds the corner, and looks out the window.

"Gum trees. Cockatoos. Hmm. Must be Australia. Oh yes. It is Australia in the winter. Cool. I am at the Scuba Shack, and it is the weekend baby!" I say to myself.

The Scripting Guy finds his contacts, assembles his underwater camera, dons his scuba undergarments under his street clothes, grabs a low-carb breakfast bar and a cup of Earl Grey tea, and is ready to go. But is the Scripting Guy really ready to go? Let's see.

So how does a Scripting Guy really know if he is ready to go diving when in Batemans Bay, Australia? He uses a script of course. (Caution! This is really a cool script! Do not read if you have an appreciation for finely crafted purpose-built scripts and a weak heart.) The Scripting Guy uses this script to ensure he does not forget anything:

$equipment = "Mask","Snorkle","Fins","BCD","Dry Suit","Hood", `
             "Gloves","Booties","Camera","Log book","C Card"
$itemCount = $equipment.count
ForEach($item in $equipment)
{
 $answer += Read-Host "Did you pack $item`? <y/n>"
}
$answerCount = [regex]::match($answer,"y+")
If($answerCount.length -eq $itemCount)
{
  "Scripting Guy, you are ready to dive!"
}
ELSE
{ 
  "Dude, you are missing stuff." 
}

I begin the script by first creating an array of items I need for cold water diving during Australian winters. The array is stored in the $equipment variable and uses line continuation to break the list into two lines, but one logical line of code. This is primarily for ease of readingreading:

$equipment = "Mask","Snorkle","Fins","BCD","Dry Suit","Hood", `
             "Gloves","Booties","Camera","Log book","C Card"

Once the array is created I next create a variable called $itemCount and set its value to the number of items in the $equipment array. I will use this value later in evaluating the Scripting Guy Dive Preparedness Value (SGDPV):

$itemCount = $equipment.count

Now I need to walk through the array and see if the item is packed. I use the += operator to concatenate my answer value. This is seen here:

ForEach($item in $equipment)
{
 $answer += Read-Host "Did you pack $item`? <y/n>"
}

Caution: We are moving into the cool part of the script. Now I need to see how many "y" answers are contained in the $answer variable. To do this, I use the regular expression pattern "y+". This pattern tells regular expressions to tell me exactly how many "y" letters are found. I use the match static method from the System.Text.RegularExpressions.Regex class and feed it both the $answer variable and my "y+" regular expression pattern. The good news here is that we have a type shortcut [regex] in Windows PowerShell for the System.Text.RegularExpressions.Regex class, so we can avoid a whole bunch of typing. This line of code is seen here:

$answerCount = [regex]::match($answer,"y+")

Now I evaluate the length from the $answerCount variable with the number contained in the $itemCount variable that contains the number of items in the $equipment array. If the two values are the same, I answered yes to each question. If they are not the same, there are one or more no’s, which means I am not ready to go diving. Here is this section of :

If($answerCount.length -eq $itemCount)
{
  "Scripting Guy, you are ready to dive!"
}
ELSE
{ 
  "Dude, you are missing stuff." 
}

Luckily, I did not forget anything, so with my scuba gear intact, I pile into Pete's car. (Pete is one of the Microsoft Australia guys I have been working with for the last few weeks on the Advanced PowerShell workshop they will be offering to their customers. It is based upon the Microsoft Press book, Windows PowerShell Scripting Guide, and it has proven to be a very popular workshop in several other countries previously haunted by Scripting Guy Ed Wilson. The awesome thing is that Pete is, in addition to being a very good scripting instructor, an open-water scuba instructor. Just the kind of guy you want for a swim buddy!)

It was just a short walk from the car to the water (according to Pete). I don't know. When wearing more than 100 pounds of scuba gear, your perception of distance can be somewhat skewed.

Upon reaching the edge of the rocks, the Scripting Guy was barely panting. Neither rock nor sand pebbles were going to deter the Scripting Guy from making the dive. We decided to put the fins on in the water, so we affected giant stride entry fins, camera in hand. Everything was cool, and we let the air out of our BCD and slowly sank. The temperature gauge read 57 degrees and our depth was 40 feet. Visibility seemed to be about 35 feet. Within minutes of reaching depth, we saw a scripting sting ray. Cool. Take a look:

GetHelp output graphic

 

Yes, it was going to be a nice dive. We glided through the cool Pacific waters, and were soon greeted by Harold. Harold is a giant grouper who as it turns out is a scripting groupie! He followed us around for most of the dive, and is actually, according to legend, a certified dive master:

GetHelp output graphic

 

 

Harold says hi. G'day, mate.