Summary: Microsoft PowerShell MVP and honorary Scripting Guy Sean Kearney continues with part 3 his five-part holiday series.

Microsoft Scripting Guy, Ed Wilson, is here. Today we have part three of a five-part series of It’s a Wonderful Shell staring George Shelley. These are written by Windows PowerShell MVP Sean Kearney. For more information about the series, Sean’s biography, and a link to the series video teaser see the Scripting Guys Announce the Holiday Lineup blog post.

Image of George Shelley

It’s a Wonderful Shell—Chapter 3

The smell of Mint tea permeated through the air as Clarence Scripto and George Shelley talked. 

In the background, our little friend had finished his thimble full of tea and had started to quietly chirp away a tune in the background. It was a lovely melody, sweet, soft and lilting. He sang his little heart (or whatever equivalent a cricket has) holding his antennae to the sky.

But since neither one of them spoke a word of Cricket, it was lost on George. Rather a shame as it would have lifted his spirits even more. But all he heard was sound akin to a cricket picking random chirps mixed in with fingernails on a chalkboard.  

They both politely excused themselves with their Mint Tea and took a walk to the datacenter where it was far quieter.

Clarence continued on with George, reminding him of how he had positively contributed in great ways with Windows PowerShell.

“Now I shall remind you again, mister, oh “man-of-constant-sorrow.” Your contributions in your eyes may be small, but they have altered lives in ways that maybe you didn’t perceive. Let’s look at the onboarding process your company had.”

George was very confused. “I didn’t fix that in any way. It’s still a slow process.”

Clarence poked him in the nose, causing George to blink. “Silly person! Why you’ve forgotten about the automatic Word document you generated with Windows PowerShell whenever you created a new user?”

It was a year ago … George remembered being very frustrated about new staff coming to him with questions about their voicemail and credentials from day one.

He once thought about writing it down in a sealed envelope, but our good friend had handwriting like a doctor who drank too much coffee and used a pen like an Etch A Sketch.

He thought about using Windows PowerShell to invoke Microsoft Word and embedding data directly into it. But putting Word on the domain controller didn’t seem to be in the guidelines of best practices anywhere. Funny that …

But George remembered an RTF file was really just a large document of ASCII text.  “… Windows PowerShell can create text files, so why not RICH text files?” he had surmised.

He created two simple files within Wordpad with the following content:

I love PowerShell, so drop another process down the pipeline baby

And another with:

Rubber Chicken

When he opened both of these files in Notepad he something in common. They both started with the following string of ASCII characters.

{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fnil\fcharset0 Consolas;}}{\*\generator Riched20 6.2.8102}\viewkind4\uc1 \pard\sa200\sl276\slmult1\f0\fs22\lang9

And completed with a single character, a parentheses.

}

Each line in the RTF document terminated with a ‘\par ‘.

So George created a very simple script in Windows PowerShell to accept the first and last name as generated by his Windows PowerShell script, the temporary network and voicemail password, as well as the login ID.

Param(

$firstname,

$lastname,

$voicemailpass,

$temporarynetworkpass,

$loginid

)

He would then add that content to a text file with the necessary bits for an RTF file, along with some basic wording.

$rtfheader=’ {\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fnil\fcharset0 Consolas;}}{\*\generator Riched20 6.2.8102}\viewkind4\uc1 \pard\sa200\sl276\slmult1\f0\fs22\lang9’

$rtffooter=’}’

$filename=$loginid+’.rtf’

ADD-CONTENT $filename –value $RTFHeader –force

ADD-CONTENT $filename –value ”Hello $firstname $lastname and welcome to Contoso\par”

ADD-CONTENT $filename –value ”Your loginid is $loginid and temporary password is $temporarynetworkpass.\par “

ADD-CONTENT $filename –value ”Your voicemail password is $voicemailpass.\par”

ADD-CONTENT $filename –value $RTFFooter

George saved the script as NEW-UserLetter.ps1 script and ran it for the sample account Mary Shelley.  Someday HR would probably ask why George kept creating and deleting his wife’s name in Active Directory.

New-UserLetter.ps1 –firstname Mary –lastname Shelley –temporarynetworkpass 25sEP45k –voicemailpass 3461 –loginid mshelley

It generated the following file.

Mshelly.rtf

When George double-clicked the file he saw the following in Wordpad on the server.

Hello Mary Shelley and welcome to Contoso

Your loginid is mshelley and temporary password is 25sEP45k

Your voicemail password is 4361

“George, you may not have realized it, but that simple script eliminated frustrations with all the new staff from that day forward. Rather than people scrambling about madly for the IT guy on their first day, they received it in their opening package from HR. 

You removed stress for new users and made manager’s lives easier with that simple script. With that simple idea in Windows PowerShell, you improved lives.

George scratched his head. “Was it possible? Could such a simple blue console have improved days in people’s lives that much?”

As the thoughts mulled around in his head, somewhere in the background Shiminy Cricket began singing a sweet soulful melody. Which, unfortunately, to humans sounds an awful lot like a 14400 baud modem negotiating.

 Thanks, Sean. Join us tomorrow for part four of It’s a Wonderful Shell.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy