Curly Blue and the meaning of scripting – Part 3


Summary: Curly Blue discovers the raw power of Cim-Instance combined with PowerShell remoting.

We continue with Curly Blue as he searches understand the meaning of scripting. He is still sitting in the office with Azura.

The co-op student, Hermie, has run off to chase something that wandered into his phone. Virus or virtual creature, nobody can ever tell.

A new request has just made its way across her desk. The CIO would like a complete inventory of all serial numbers of the company’s workstations.

Curly just rolled his eyes. “Over 5,000 workstations! Just where do we even start?”

Azura noted his displeasure at the thought of being trapped in the office for hours with various co-op students fighting over pizza. “Ah yes, you’re imagining the worst. You know there’s a far easier way, don’t you?”

He looked over at her. “I’m guessing you’re going to say it is something related to PowerShell?”

She nodded. “The serial numbers and all data that’s stored in Windows in the Common Information Model and retrievable easily with PowerShell.”

Azura fired up a cmdlet on the screen to demonstrate the purpose. “With PowerShell, I can run this one cmdlet to see all default classes that are available to query.”

Get-CimClass

Curly felt his eyeballs fall onto the table as the raw dump of data poured onto the screen.

Results from Get-CimClass

“Just where do you begin with that?” he balked.

“Well,” Azura began, “The model is quite well documented, and there are a lot of older WMI entries still existing but extended out to be view in the CIM. Mostly I just go online and sometimes search for older VBScripts that do the same thing. If you see ‘win32_’ something or other that’s usually the key entry.”

“BingFu! Now that’s something I understand!” Curly burst out.

“Well, on top of that, most of the names actually make sense! So, my first time out, I just dumped all of them to a CSV file. It’s the same process Hermie used with the HomeDirectory in Active Directory earlier.”

Get-CimClass | Export-CSV CimClassList.csv

“I did a little poking around and found a class called Win32_Bios, which has exactly what we are looking for. I can use the following cmdlet to ask a class a question.”

Get-CimInstance Win32_Bios

Curly noted the information on the screen.

Results from Get-CimInstance Win32_Bios

“This is cool, but just how are you going to get that from every system?”

“The CIM cmdlets can also,” Azura went about dramatically, “connect to other remote CIM instances and gather data.”

She ran the following cmdlet to connect a remote system and pull its serial number.

$S=New-CIMSession -computername ContosoWs1 -Classname Win32_Bios

Curly thought to himself. “So, we could just somehow send an entire list to this Cmdlet, grab the output, and maybe export it to a CSV file?”

“You guessed it. We could even, if we got creative, use one cmdlet to send the results as an email back to the Director. This means that you wouldn’t have to actually be here when the work finished.”

Curly Blue was really interested in learning a whole lot more about PowerShell after he saw how easy it was and just how much work he could accomplish so easily. He was wondering what would happen next.

I invite you to follow the Scripting Guys on Twitter and Facebook. If you have any questions, send email to them at scripter@microsoft.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

Comments (0)

Skip to main content