Summary: Seven years ago, “Hey, Scripting Guy!” was approached by a member of the community to see if we would be interested in doing something a little fun for the holidays. The result was a seven-part series called “A PowerShell Carol.”
So when we were approached continuously in following years, we allowed this madness to continue! The tradition continued on with the “Blues” in Blueville and Curly Blue, amongst others, doing a twist on popular holiday stories. The community even dared to touch upon classic tales, with “Oliver Script,” a “twist” on another famous story by Mr. Dickens.
And now, we bring you the 8th annual “Hey, Scripting Guy!” holiday special.
Script Wars: The Farce Awakens
It is a period of confusion for the software industry. Software companies from eons in the past had computer systems that contained rudimentary operating systems and very few commercial, off-the-shelf solutions. Software and Infrastructure as a Service were unheard of in these days.
Over time the landscape changed and improved. New factions, such as the IT professional, split apart from the old, as systems became more user friendly and business needs changed. Automation formed upon the horizon.
But the early automation technologies were challenging, and required strong training to use them. Amongst this came best practices and top-down software design.
The old republic of the IT professionals has begun to enter retirement, and the use of older solutions such as vbScript has begun to fade.
A new breed of young upstarts has appeared, taking advantage of newer and simpler solutions such as Windows PowerShell. This story is of one such young upstart, a brilliant and gifted individual called Rey Skyworker.
Her story begins as we meet her discussing the concepts and history of automation with her instructor, one Ben Kerberosie.
Ben and Rey were sitting together, discussing the use of Windows PowerShell to clean up Active Directory.
“Rey,” the instructor asked as he looked over his bespectacled and soldered glasses, “If I were to try to clean up an Organizational Unit in Active Directory, what types of Cmdlets would I use?”
The student thought about it for a moment. “I would probably use a Get-ADUser Cmdlet, and then pipe that to a Remove-ADObject.”
Ben pulled over some code onto his screen. “A sample like this would work then?”
Get-Aduser -Filter * -searchbase $TargetOU | Remove-ADObject -confirm:$False
Rey was about to nod her head when she noticed something. “Technically the script works, but I’m not sure I would put this into production.”
The old Master looked over her. “Why is that? Don’t be afraid to speak your mind.”
Rey looked over at the screen. “First, I would have never used the ‘*’, which is a wildcard character. If for any reason the $DestinationOu was targeted at the root, that would have had a major impact to production. Personally, I would have written that parameter as a separate object.”
She showed some sample script to Ben.
$ADFilter=’Name -like “*smith”‘
Get-Aduser -Filter $ADFilter -searchbase $TargetOU | Remove-ADObject -confirm:$False
“This…,” she noted, “would at least limit the impact to the only users with ‘Smith’ in the name. I could write a more advanced filter, but using ‘*’ would not be a good career option.”
“The second thing I noticed is a lack of the ‘-whatif’ parameter. Whenever I write a PowerShell script, I like to have that option on anything that does something destructive. That is, if the Cmdlet supports it.”
“Good thinking, but why not just use a ‘$True’ on the confirm switch?” Ben noted.
“Confirm:$True would pause for each execution of the Cmdlet, but the ‘whatif’ parameters shows me quickly a count of how many would try to execute. It’s a good way to see immediately if I am removing 1 or 1,000,000 accounts. I would immediately know that I didn’t trap for something in my code.”
She expanded upon her script with this example.
$ADFilter=’Name -like “*smith”‘
Get-Aduser -Filter $ADFilter -searchbase $TargetOU | Remove-ADObject -confirm:$False -whatif
“Ahhhh…” the old one smiled. “I see you are strong in the ways of The Farce.”
Rey scratched her head, puzzled. “The wha… is that some kind of joke?”
“Nope. The Farce is what I use to describe the differences between a good scripter and a bad one. Really, “bad” one is not the correct word, it would be ‘One who is not thinking before they execute’.”
Rey was interested. “Tell me more…”
“Well…,” Ben began, “In the old days of vbScript, we had developers writing scripts and automation because it wasn’t something the average IT professional was up to. It was a pretty intense little language.”
Rey remembered seeing the old vbScripts in some virtual machines from training. They were quite complex, with many checks and balances.
“In the modern world we have Windows PowerShell, which is incredibly easy to use. But it’s also easy to make mistakes. “
“The other challenge is the need of the business to get things into production fast, while making sure checks and balances are in place with a limited budget and new workers. This is the Farce. But if you are strong in its ways, you can write scripts quickly, but also know how to put in simple checks and balances to keep your code strong in the light side of the Farce.”
Ben looked over at Rey. “You must continue your training in the ways of the Farce if you are to come with me to…”
“ALDERAAN?!?!?!” she burst out excitedly.
“Well…,” Ben looked over, “actually Contoso Holly Jolly Hat Company. I have need for some new help desk staff, and I would love for you to start with us.”
Rey was excited. Her first real job in IT, and just in time for the holidays. All those days of hard work were paying off. She was going to get paid doing what she loved to do.
Stay tuned tomorrow, when we continue the story of “Script Wars: the Farce Awakens.”
Sean Kearney, Premiere Field Engineer
Enterprise Services Delivery, Secure Infrastructure