Curly Blue and the meaning of scripting – Part 2
Summary: Curly Blue learns how to use built-in PowerShell script examples in Windows.
Yesterday we met our new friends, Curly Blue and Linux. Curly had started his new job as a IT Professional at Contoso.
The challenge for poor Curly was that he had never learned scripting or, for that matter, gotten into the spirit of it. He had mastered a unique talent of hyper-active data entry skills combined with keyboard shortcuts.
He was now walking to the Office of Azura. She is in charge of managing the migration of the company resources to the cloud. Today she is working with a co-op student, Hermie.
“Our big challenge this week is to identify the location of all the home folders from our user environment in Active Directory,” she says to the young co-op.
Curly overheard this and just tried to picture the task ahead of the young fellow. With over 5,000 users in the environment, he mumbled “Oh no… so many screenshots!”
Azura looked over at Curly. “Why would you say that? Haven’t you checked out the Active Directory Administrative Center?”
He was quite puzzled. “Why, yes, it’s one of the new features that was introduced in Windows Server 2008 R2. I find it a far nicer interface to work in. But still, won’t you need screenshots?”
Hermie popped up. “Not really. If I use Windows PowerShell and the Active Directory module, I can do it really quite quickly.”
Again, poor Curly was shaking his head. “Okay, PowerShell again. I get that it does things quickly, but won’t it take time to learn how to do this first?”
Azura tapped her chin thoughtfully. “I guess you didn’t notice the big change with the Active Directory Administrative Center that came about in Windows Server 2012?”
Curly was shaking his head in confusion. “What ‘big change’? Cosmetically, the console looks the same. I’m not sure what you’re getting at.”
“Can I show him?” Hermie was so excited “The first time Azura showed me this trick, I was blown away! I used to say the same thing!”
He opened the with the Active Directory Administrative Center to pull up one of Curly Blue’s users in Active Directory.
Curly sat there confused. “Where’s this ‘really cool’ part?”
Hermie pointed excitedly to the little caret on the far-right lower corner of the Active Directory Administrative Center. “I totally missed this my first 50 times! When Azura showed me this, I fell off the chair!”
He clicked the little icon to the far right side of the words “WINDOWS POWERSHELL HISTORY”
Curly nearly dropped his coffee. “Is that what I think it is?” glancing at the following screen.
Azura confirmed it. “It most certainly is. Everything that click in the Active Directory Administrative Center is actually a logged PowerShell cmdlet. So, that means that if you do it once in the Active Directory Administrative Center, there is an example of the script that you need to run.”
Hermie nodded. “This is why, when Azura asked for this report, I already had a copy of the cmdlet that does this stored in my batch of ready-to-use scripts. I can run this one cmdlet to pull down a list of all the users from Active Directory and the key properties we need, which is the HomeFolderPath.”
Get-ADUser -filter * -properties HomeDirectory -resultsetsize 5000
Curly glances at a list that populated the length of the screen. He could see within that list the value for the HomeDirectory.
“But the coolest part?” Hermie’s eyes lit up like a 48 port 10 gig switch. “I can make this immediately into a file for Excel!”
He watched as Hermie added in the Export-CSV cmdlet to the original output.
Get-ADUser -filter * -properties HomeDirectory -resultsetsize 5000 | Export-CSV HomeDirs.csv
Curly looked over at Azura. “How long did it take for him to figure that out?”
She paused thoughtfully. “Maybe the time it took you to ask the question. PowerShell really *is* very easy. It’s not like VBScript was or the console apps. It’s very consistent in its approach.”
Curly sits there intrigued. For a system that he’d never used before, this PowerShell looked very tempting to get started in.
Visit tomorrow to see how much Curly checks into this new PowerShell universe that is unfolding before his eyes.
I invite you to follow the Scripting Guys on Twitter and Facebook. If you have any questions, send email to them at email@example.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow.
Until then, always remember that with Great PowerShell comes Great Responsibility.
Sean Kearney Honorary Scripting Guy Cloud and Datacenter Management MVP