{"id":2751,"date":"2011-02-06T20:39:23","date_gmt":"2011-02-06T20:39:23","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2011\/02\/06\/does-your-hard-work-advance-the-ecosystem\/"},"modified":"2019-02-18T13:05:50","modified_gmt":"2019-02-18T20:05:50","slug":"does-your-hard-work-advance-the-ecosystem","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/does-your-hard-work-advance-the-ecosystem\/","title":{"rendered":"Does Your Hard Work Advance the Ecosystem?"},"content":{"rendered":"<p>The Lync PowerShell Blog recently posted a <a href=\"http:\/\/blogs.technet.com\/b\/csps\/archive\/2010\/12\/08\/excelenableusers.aspx\">fairly chewy piece<\/a> that described how to enable users in bulk when given an XLS file as input.<\/p>\n<p><a href=\"http:\/\/www.jasonhelmick.com\/journal\/2011\/2\/6\/admins-unite-against-slow-powershell-adoption.html\">Jason Helmick responded<\/a>, saying:<\/p>\n<blockquote>\n<p>Instead of your incredible code that no admin would even begin to understand or even be able to write, let\u2019s do the same thing, in one line. (Note: This is an educated PowerShell admin, or any typical Unix guy.)<\/p>\n<p><strong>Step 1:<\/strong> Admin receives xls from HR.&#160; They then proceed to use Excel to convert it to CSV.&#160; Total time, 10 seconds.<\/p>\n<p><strong>Step 2:<\/strong> They then type the following one-liner:<\/p>\n<p><strong>Import-CSV C:\\Scripts\\NewUsers.csv | %{Enable-CsUser -Identity $_.Name -RegistrarPool $_.RegistrarPool -SipAddress $_.SipAddress}<\/strong><\/p>\n<\/blockquote>\n<p>In fact, if Enable-CsUser supports <a href=\"http:\/\/get-powershell.com\/2008\/10\/16\/v2-script-cmdlets\/\">ValueFromPipelineByPropertyName<\/a> for the Name, RegistrarPool and SipAddress parameters, it would just come down to this:<\/p>\n<blockquote>\n<p>Import-Csv c:\\scripts\\NewUsers.csv | Enable-Csuser<\/p>\n<\/blockquote>\n<p>There are definitely a lot of people that program in PowerShell despite functionality that already exists. A perfect example is the C# developer that writes a complex directory recursion script against the .NET file APIs despite &quot;dir -recurse&quot; being right under their nose.<\/p>\n<p>However, PowerShell doesn&#8217;t have anything built-in that lets you read XLS files. If you need to automate this scenario (another core promise of PowerShell), manually opening Excel to convert it to a CSV will be a non-starter. From that perspective, the Linc-PowerShell blog post genuinely moves the ball forward for admins everywhere.<\/p>\n<p>One of our core beliefs is in the trickle-down effect. Now that somebody&#8217;s done the leg work of digging into an XLS spreadsheet, perhaps other admins will be able to! If they&#8217;re proficient at copy + paste, they can hopefully wedge this into their own scenarios.<\/p>\n<p>What really works out well is when another enterprising admin gets stick of copying this code everywhere and writes a wrapper: <strong>Import-Xls<\/strong>. This function could do the same as Import-Csv, but use this COM object technique to extract the data. Then, they post it on <a href=\"http:\/\/poshcode.org\/\">poshcode.org<\/a>, and the entire ecosystem gets more efficient. (As a side note, an alternative to dealing with Excel\u2019s COM object is included in the PowerShell Cookbook, and given here: <a title=\"http:\/\/poshcode.org\/2188\" href=\"http:\/\/poshcode.org\/2188\">http:\/\/poshcode.org\/2188<\/a>)<\/p>\n<p>At that point, dealing with XLS files again becomes a one-liner: <strong>Import-Xls c:\\scripts\\NewUsers.xls | Enable-CsUser<\/strong>.<\/p>\n<p>When you write something great that advances the state of PowerShell, why not take the few moments to wrap it in a reusable function for the world to enjoy?<\/p>\n<p>&#160;<\/p>\n<p>Lee Holmes [MSFT]   <br \/>Windows PowerShell Development<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Lync PowerShell Blog recently posted a fairly chewy piece that described how to enable users in bulk when given an XLS file as input. Jason Helmick responded, saying: Instead of your incredible code that no admin would even begin to understand or even be able to write, let\u2019s do the same thing, in one [&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":[],"class_list":["post-2751","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>The Lync PowerShell Blog recently posted a fairly chewy piece that described how to enable users in bulk when given an XLS file as input. Jason Helmick responded, saying: Instead of your incredible code that no admin would even begin to understand or even be able to write, let\u2019s do the same thing, in one [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/2751","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=2751"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/2751\/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=2751"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=2751"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=2751"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}