September 22nd, 2008

Hey, Scripting Guy! Australian Dispatch #1: How Does a Scripting Guy Pack for a Trip?

Three o’clock in the morning is early for anyone, even a scripting guy. Yet there was this persistent annoying ringing sound that kept trying to interrupt my short-lived sleep. At last I was able to put a name to the intrusion. Alarm clock. It is time to get up. Today I begin the process of going to Australia. The flight goes from Charlotte, North Carolina, to Chicago, Illinois, to Los Angeles, California, to Nadi, and finally to Sydney, Australia. Uh, Nadi? Yep, Nadi is in Fiji and the stop-over there will break up the trip nicely. I packed everything last night, and loaded the scriptmobile: dive bag, dive camera, suitcase, and laptop bag. Yep, it’s all there. So how does a Scripting Guy make sure he does not forget anything? Well, he writes a script (duh). I store the items I am taking into an array. Use the Read-Host cmdlet to elicit feedback from the command line, and then use the contains method to see if everything is groovy. The script is seen here:

$stuff = "DiveBag", "DiveCamera", "SuitCase","LapTop"
Foreach($thing in $stuff)
{
 $CheckEd += Read-Host -Prompt "Did you remember $thing`? < y,n >"
}
If($CheckEd.contains("n"))
{
 "You forgot something"
}
ELSE
{
 "Looks like you are all packed!"
}

The script uses a couple of pretty cool tricks (if I do say so myself). It starts off innocently enough by creating an array. In Windows PowerShell if you want an array, you simply specify multiple items to the value of the variable. This is seen here:

$stuff = "DiveBag", "DiveCamera", "SuitCase","LapTop"

In Windows PowerShell as in VBScript, to walk through an array we use a ForEach statement. The difference, of course, is the curly brackets. One feature I really like about Windows PowerShell is the += operator. When I use $CheckEd += something else, it is the same as saying $CheckEd = $CheckEd + something else. It is less typing, and a little more intuitive. To elicit input from the prompt I use the Read-Host cmdlet. This section of the script is seen here:

Foreach($thing in $stuff)
{
 $CheckEd += Read-Host -Prompt "Did you remember $thing`? < y,n >"
}

The really cool part of the script is the way I see if there were any no responses. The letters that get concatenated as a result of the prompting for responses are instances of a System.String class. The String class has a method named Contains. If we find a match, the method returns true. Otherwise, it will return false. If the $CheckEd string contains the letter n, we print out a statement that says we have forgotten something. Otherwise, we print out a string that says we are all packed. This section of the script is seen here:

If($CheckEd.contains("n"))
{
 "You forgot something"
}
ELSE
{
 "Looks like you are all packed!"
}

It will take two days to get to Sydney. I love Sydney. Last year I was there a couple of times, and each trip was special-each much anticipated-and this trip promises to be no different. I will be in Oz for nearly a month. The purpose is to do a train-the-trainer of some Microsofties. they will be trained to deliver my Advanced Windows PowerShell workshop which is based loosely around my new PowerShell Scripting Guide book. Along the way I will also be doing a couple of deliveries of the workshop: one in Sydney and one in Canberra. I also plan to do some scuba diving while I am down there.

Back to my morning. So how does a scripting guy wake up in the morning? Easy. I use the Get-Date cmdlet to create a System.DateTime object that represents the time I wish to wake up. I use a do while statement that loops around until the current time matches the desired time. When the time is reached, I sound the alarm by using the `a character, which generates a system beep. The script is shown here:

$dtmTime = get-date -h 03 -mi 00 -s 00
do {$dtmCurrent = Get-Date -DisplayHint time
"The current time is " + $dtmCurrent
"counting to " + $dtmtime
start-sleep -s 60
} while ($dtmCurrent -lt $dtmTime)
"time reached `a"

One thing I like doing in Windows PowerShell is using the Get-Date cmdlet to create a DateTime object. This is similar to the DateSerial function from VBScript. But the thing that is cool is it is the same cmdlet performing multiple actions. The Get-Date cmdlet also provides a great amount of control over the way in which the DateTime object is displayed. The easiest to use is the DisplayHint parameter. You can supply three values for this parameter: Date, Time, DateTime. The more complicated ways of displaying time will appear in a future Hey Scripting Guy article.

In VBScript we used the wscript.sleep command to pause execution of a script. It took a value in milliseconds. In Windows PowerShell we use the Start-Sleep cmdlet to do the same thing. If we want to sleep in milliseconds we use -Milliseconds parameter. If we wish to sleep in seconds then we use the -Seconds parameter.

It is a beautiful day to fly. The early morning flight from Charlotte to Chicago left on time, and quickly climbed above the low-level clouds that hugged the soft rolling hills of Mecklenburg County like a down comforter. At 450 miles per hour we raced toward Chicago, but were unable to outrun the rapid onset of another new day. On a small plane and a short-hop flight, the Scripting Guy does not generally bother dragging out his ScriptTop computer; instead he prefers to snuggle up with Mickey Spillane novels. (He would bring out the ScriptTop computer except that the seats are tight enough that he is paranoid that some tall guy in the seat in front of him will layback and crush the monitor like yesterday’s empty soda can.)

Somewhere over Virginia the sky off the right side of the plane turned red. The comforter still covered the more rugged hills of Virginia, and it glowed fireball red, with traces of orange and yellow thrown in for good measure. Off the left side of the plane, the full moon stared down. Defiantly fighting for attention, refusing to go silently into that gentle quiet day, it fought the losing battle until finally subsiding for the day as we reached Chicago.

Errrrrcchhhhhhhhh. “Welcome to Chicago.” The voice sounded hollow and far away as it seemingly radiated from the thin walls of the aircraft. There was virtually no traffic as we taxied to the gate. (Why is it called taxiing anyway? There are no cabs involved in the process. I would imagine it would more accurately called driving. Just a thought.) The Scripting Guy grabbed his ScriptTop and boogied down the jet bridge. (Dude, it looks like a piece of metal laid between two uneven surfaces. I thought a jet bridge was what the planes in Dallas take when they arrive from the south to get them to the terminal.) Oh well, I had an hour to kill and because I am on a diet, I avoided the plethora of fast food places all proffering empty calories and headed for the club lounge where I had a cup of mint tea and an apple.

While checking my e-mail on my smart phone, I saw one from Jit in Australia. He says that while it is true that the Snowy River area stretches nearly to Canberra, the area we see on TV and in movies is about 12 hours from Canberra. Bummer. I was hoping to get some pictures of Brumbies, sit outside under a shade tree, and write a couple of scripts. Oh, well. I will be going through Kangaroo Valley, so maybe I can get a picture of a roo—they really are cute. Look like great big rabbits.

Got upgraded to first class for the flight to Los Angeles—woohoo! The good news about such an upgrade is that the seats have power outlets, so I can use my ScriptTop. The movie was Speed Racer, an experience to which I did not avail myself. Dude, with a front row seat, plenty of leg room, a nice size tray to work on, and a power outlet, what do you think a Scripting Guy did for four hours? Talk to you later.

Author

0 comments

Discussion are closed.