{"id":10311,"date":"2006-05-11T15:22:00","date_gmt":"2006-05-11T15:22:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2006\/05\/11\/powershells-script-center-problem\/"},"modified":"2019-02-18T13:21:42","modified_gmt":"2019-02-18T20:21:42","slug":"powershells-script-center-problem","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/powershells-script-center-problem\/","title":{"rendered":"PowerShell&#039;s Script Center problem"},"content":{"rendered":"<p class=\"MsoNormal\"><font face=\"Arial\" size=\"2\"><span>Fellow Scripters,<\/span><\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Arial\" size=\"2\"><span><\/span><\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Arial\" size=\"2\"><span>We\u2019ve heard that some of you think our PowerShell sample scripts on the TechNet Script Center stink. Do you have any idea how much that hurts? We slave over hot keyboards day in and day out trying to help you ungrateful scoundrels learn more about scripting. And how do you repay us? Nasty emails and smear campaigns, that\u2019s how\u2026.just a sec\u2026what\u2019s that?&#8230;what do you mean they have a point? Really? Oh. OK.<\/span><\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Arial\" size=\"2\"><span><\/span><\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Arial\" size=\"2\"><span>Ahem. Yes, well then\u2026as I was saying, in my official capacity as someone writing an email message to a fellow named Lee, that I hope he\u2019ll post on a blog for me, I\u2019m here to explain why the PowerShell sample scripts on the Script Center are not at all elegant and basically look like VBScripts translated into PowerShell scripts. For those of you who haven\u2019t experienced the horror first hand (you might want to chase your offspring out of the room at this stage), here\u2019s one of the offending scripts. <\/span><\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Arial\" size=\"2\"><span><\/span><\/font><\/p>\n<pre><font face=\"Lucida Console\" size=\"1\"><span>$strComputer = \".\"<br \/><\/span><\/font><font face=\"Lucida Console\" size=\"1\"><span>$colItems = get-wmiobject -class \"Win32_LoadOrderGroup\" -namespace \"root\\CIMV2\" `<br \/><\/span><\/font><font face=\"Lucida Console\" size=\"1\"><span>-computername $strComputer<br \/><br \/><br \/><br \/><\/span><\/font><\/pre>\n<pre><font face=\"Lucida Console\" size=\"1\"><span><\/span><\/font><font face=\"Lucida Console\" size=\"1\"><span>foreach ($objItem in $colItems) {<br \/><\/span><\/font><font face=\"Lucida Console\" size=\"1\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; write-host \"DriverEnabled: \" $objItem.DriverEnabled<br \/><\/span><\/font><font face=\"Lucida Console\" size=\"1\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; write-host \"GroupOrder: \" $objItem.GroupOrder<br \/><\/span><\/font><font face=\"Lucida Console\" size=\"1\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; write-host \"Name: \" $objItem.Name<br \/><\/span><\/font><font face=\"Lucida Console\" size=\"1\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; write-host<br \/><\/span><\/font><font face=\"Lucida Console\" size=\"1\"><span>}<\/span><\/font><\/pre>\n<p class=\"MsoNormal\"><font face=\"Arial\" size=\"2\"><span>If you happen to be into this sort of vulgarity, here\u2019s a link to the entire repository of the beasts: <a title=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/scripts\/msh\/default.mspx\" href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/scripts\/msh\/default.mspx\">http:\/\/www.microsoft.com\/technet\/scriptcenter\/scripts\/msh\/default.mspx<\/a>. <\/span><\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Arial\"><span>So what, exactly, were we thinking? And when are we going to get our act together and post some elegant scripts? Don\u2019t we know that <span>PS:&gt;get-wmiobject <font face=\"Lucida Console\">Win32_LoadOrderGroup<\/font><\/span> would have accomplished the same thing and demonstrated some of the Power in PowerShell?<\/span><\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Arial\" size=\"2\"><span><\/span><\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Arial\" size=\"2\"><span>Here\u2019s the deal. Our performance is judged by the number of lines of script we write. We needed to figure out a way to keep the line count up and the bonuses rolling in. (you would not believe what it costs to fill up a Ferrari these days!). So, we told management that we wanted to create PowerShell scripts that looked exactly like the typical VBScripts you find on Script Center. <\/span><\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Arial\" size=\"2\"><span><\/span><\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Arial\" size=\"2\"><span>We spun this tale about how we wanted to help ease our beloved Script Center customers into the PowerShell world by showing them how their existing knowledge translates easily to PowerShell. They can still set a strComputer variable to \u201c.\u201d to reference the local machine, they still have a For Each loop, there\u2019s still a statement that let\u2019s them display information on the screen. &nbsp;Heck, if they look at the two scripts side-by-side, they\u2019ll surely see the parallel statements and thereby be gently introduced to a bit of PowerShell syntax. <\/span><\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Arial\" size=\"2\"><span><\/span><\/font><\/p>\n<pre><font face=\"Lucida Console\" size=\"1\"><span>On Error Resume Next<br \/><\/span><\/font><font face=\"Lucida Console\" size=\"1\"><span>strComputer = \".\"<br \/><\/span><\/font><font face=\"Lucida Console\" size=\"1\"><span>Set objWMIService = GetObject(\"winmgmts:\" _<br \/><\/span><\/font><font face=\"Lucida Console\" size=\"1\"><span>&nbsp;&nbsp;&nbsp; &amp; \"{impersonationLevel=impersonate}!\\\\\" &amp; strComputer &amp; \"\\root\\cimv2\")<br \/><\/span><\/font><font face=\"Lucida Console\" size=\"1\"><span>Set colItems = objWMIService.ExecQuery(\"Select * from Win32_LoadOrderGroup\")<br \/><\/span><\/font><font face=\"Lucida Console\" size=\"1\"><span>&nbsp;<br \/><\/span><\/font><font face=\"Lucida Console\" size=\"1\"><span>For Each objItem in colItems<br \/><\/span><\/font><font face=\"Lucida Console\" size=\"1\"><span>&nbsp;&nbsp;&nbsp; Wscript.Echo \"Driver Enabled: \" &amp; objItem.DriverEnabled<br \/><\/span><\/font><font face=\"Lucida Console\" size=\"1\"><span>&nbsp;&nbsp;&nbsp; Wscript.Echo \"Group Order: \" &amp; objItem.GroupOrder<br \/><\/span><\/font><font face=\"Lucida Console\" size=\"1\"><span>&nbsp;&nbsp;&nbsp; Wscript.Echo \"Name: \" &amp; objItem.Name<br \/><\/span><\/font><font face=\"Lucida Console\" size=\"1\"><span>&nbsp;&nbsp;&nbsp; Wscript.Echo<br \/><\/span><\/font><font face=\"Lucida Console\" size=\"1\"><span>Next<\/span><\/font><\/pre>\n<p class=\"MsoNormal\"><font face=\"Arial\" size=\"2\"><span>Of course we expected to be found out eventually and, apparently, eventually has arrived early this year. So, what are we going to do about it? We\u2019ll we\u2019re not going to take down those existing scripts anytime soon. (we need the line count, remember?). We are, however, working another scam. We\u2019re soliciting elegant PowerShell scripts from internal folks at Microsoft who do have a clue. This is brilliant. We claim that we want to \u201cleverage their expertise\u201d or benefit from their \u201cunderstanding of real-world customer scenarios\u201d or some other buzz-word-laden suck up sentence and they do our work for us. <\/span><\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Arial\" size=\"2\"><span><\/span><\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Arial\" size=\"2\"><span>Unfortunately, we still have to organize what we get and do the production work required to get the samples posted. We\u2019re a tiny little team and we\u2019re currently working on improving the command line help in PowerShell. Though we\u2019ve tried, we can\u2019t figure out a way to make that work easier or to get someone else to do it for us. So, the new PowerShell script samples are on hold until we\u2019re done. <\/span><\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Arial\" size=\"2\"><span><\/span><\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Arial\" size=\"2\"><span>Now, in case you haven\u2019t picked it up, we\u2019re pretty open to benefiting from the hard work of other people. If you\u2019ve got some elegant PowerShell scripts that you\u2019d like to see on the Script Center, we\u2019d like to help you help us. Just click on the following link, click Submit a Script, agree to donate all of your future earnings to us and fill out the form. No promises, but we\u2019ll do our best to post the submissions (only if they\u2019re elegant of course).<\/span><\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Arial\" size=\"2\"><span><\/span><\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Arial\" size=\"2\"><span><a title=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/csc\/default.mspx\" href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/csc\/default.mspx\">http:\/\/www.microsoft.com\/technet\/scriptcenter\/csc\/default.mspx<\/a><\/span><\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Arial\" size=\"2\"><span><\/span><\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Arial\" size=\"2\"><span>&nbsp;<\/span><\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Arial\" size=\"2\"><span>Many thanks (ungrateful scoundrels),<br \/><\/span><\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Arial\" size=\"2\"><span>Dean Tsaltas<\/span><\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Arial\" size=\"2\"><span>&nbsp;<\/span><\/font><font face=\"Arial\" size=\"2\"><span>Official Spokesman for the Script Center team <br \/><\/span><\/font><font face=\"Arial\" size=\"2\"><span>\u2026.on this one particular, inconsequential issue<br \/><\/span><\/font><font face=\"Arial\" size=\"2\"><span>\u2026.only because the rest of the team didn\u2019t have time and Lee demanded something by the end of the day<\/span><\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Arial\" size=\"2\"><span>[Edit: Fixed some typos]<br \/>PSMDTAG:TYPE:WMI: <\/span><\/font><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fellow Scripters, We\u2019ve heard that some of you think our PowerShell sample scripts on the TechNet Script Center stink. Do you have any idea how much that hurts? We slave over hot keyboards day in and day out trying to help you ungrateful scoundrels learn more about scripting. And how do you repay us? Nasty [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[20],"class_list":["post-10311","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-typewmi"],"acf":[],"blog_post_summary":"<p>Fellow Scripters, We\u2019ve heard that some of you think our PowerShell sample scripts on the TechNet Script Center stink. Do you have any idea how much that hurts? We slave over hot keyboards day in and day out trying to help you ungrateful scoundrels learn more about scripting. And how do you repay us? Nasty [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/10311","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=10311"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/10311\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=10311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=10311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=10311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}