{"id":81145,"date":"2016-12-23T00:01:42","date_gmt":"2016-12-23T08:01:42","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/?p=81145"},"modified":"2019-02-18T09:10:17","modified_gmt":"2019-02-18T16:10:17","slug":"curly-blue-and-the-meaning-of-scripting-part-3","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/curly-blue-and-the-meaning-of-scripting-part-3\/","title":{"rendered":"Curly Blue and the meaning of scripting \u2013 Part 3"},"content":{"rendered":"<p><strong>Summary<\/strong>: Curly Blue discovers the raw power of Cim-Instance combined with PowerShell remoting.<\/p>\n<p>We continue with Curly Blue as he searches understand the meaning of scripting. He is still sitting in the office with Azura.<\/p>\n<p>The co-op student, Hermie, has run off to chase something that wandered into his phone. Virus or virtual creature, nobody can ever tell.<\/p>\n<p>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\u2019s workstations.<\/p>\n<p>Curly just rolled his eyes. \u201cOver 5,000 workstations! Just where do we even start?\u201d<\/p>\n<p>Azura noted his displeasure at the thought of being trapped in the office for hours with various co-op students fighting over pizza. \u201cAh yes, you\u2019re imagining the worst. You know there\u2019s a far easier way, don\u2019t you?\u201d<\/p>\n<p>He looked over at her. \u201cI\u2019m guessing you\u2019re going to say it is something related to PowerShell?\u201d<\/p>\n<p>She nodded. \u201cThe serial numbers and all data that\u2019s stored in Windows in the Common Information Model and retrievable easily with PowerShell.\u201d<\/p>\n<p>Azura fired up a cmdlet on the screen to demonstrate the purpose. \u201cWith PowerShell, I can run this one cmdlet to see all default classes that are available to query.\u201d<\/p>\n<p style=\"padding-left: 60px\"><code>Get-CimClass<\/code><\/p>\n<p>Curly felt his eyeballs fall onto the table as the raw dump of data poured onto the screen.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1-HSG-122316.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1-HSG-122316.png\" alt=\"Results from Get-CimClass\" width=\"553\" height=\"313\" class=\"alignnone size-full wp-image-81155\" \/><\/a><\/p>\n<p>\u201cJust where do you <u>begin<\/u> with that?\u201d he balked.<\/p>\n<p>\u201cWell,\u201d Azura began, \u201cThe 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 \u2018win32_\u2019 something or other that\u2019s usually the key entry.\u201d<\/p>\n<p>\u201cBingFu! Now <u>that\u2019s<\/u> something I understand!\u201d Curly burst out.<\/p>\n<p>\u201cWell, 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\u2019s the same process Hermie used with the HomeDirectory in Active Directory earlier.\u201d<\/p>\n<p style=\"padding-left: 60px\"><code>Get-CimClass | Export-CSV CimClassList.csv<\/code><\/p>\n<p>\u201cI 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.\u201d<\/p>\n<p style=\"padding-left: 60px\"><code>Get-CimInstance Win32_Bios<\/code><\/p>\n<p>Curly noted the information on the screen.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2-HSG-122316.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2-HSG-122316.png\" alt=\"Results from Get-CimInstance Win32_Bios\" width=\"660\" height=\"148\" class=\"alignnone size-full wp-image-81165\" \/><\/a><\/p>\n<p>\u201cThis is cool, but just how are you going to get that from every system?\u201d<\/p>\n<p>\u201cThe CIM cmdlets can also,\u201d Azura went about dramatically, \u201cconnect to other remote CIM instances and gather data.\u201d<\/p>\n<p>She ran the following cmdlet to connect a remote system and pull its serial number.<\/p>\n<p style=\"padding-left: 60px\"><code>$S=New-CIMSession -computername ContosoWs1 -Classname Win32_Bios<\/code><\/p>\n<p>Curly thought to himself. \u201cSo, we could just somehow send an entire list to this Cmdlet, grab the output, and maybe export it to a CSV file?\u201d<\/p>\n<p>\u201cYou 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\u2019t have to actually be here when the work finished.\u201d<\/p>\n<p>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.<\/p>\n<p>I invite you to follow the Scripting Guys on <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> and <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to them at <a target=\"_blank\" href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a>, or post your questions on the <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingforum\">Official Scripting Guys Forum<\/a>. See you tomorrow.<\/p>\n<p>Until then, always remember that with Great PowerShell comes Great Responsibility.<\/p>\n<p><strong>Sean Kearney\n<\/strong>Honorary Scripting Guy\nCloud and Datacenter Management MVP<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[568,685,641],"tags":[56,154,45],"class_list":["post-81145","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hey-scripting-guy","category-scripting-techniques","category-windows-powershell","tag-guest-blogger","tag-sean-kearney","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>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 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/81145","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=81145"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/81145\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=81145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=81145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=81145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}