{"id":13281,"date":"2011-07-18T00:01:00","date_gmt":"2011-07-18T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2011\/07\/18\/install-the-pscx-and-80-new-cmdlets-to-ease-powershell-use\/"},"modified":"2011-07-18T00:01:00","modified_gmt":"2011-07-18T00:01:00","slug":"install-the-pscx-and-80-new-cmdlets-to-ease-powershell-use","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/install-the-pscx-and-80-new-cmdlets-to-ease-powershell-use\/","title":{"rendered":"Install the PSCX and 80 New Cmdlets to Ease PowerShell Use"},"content":{"rendered":"<p><b>Summary<\/b>: Install the PSCX and get 80 new cmdlets to ease Windows PowerShell use.<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\" \/>Hey, Scripting Guy! You have been spending quite a bit of time recently talking about functions and modules and the like. What is the big deal, and where would I find such modules?<\/p>\n<p>&mdash;KF<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\" \/>Hello KF,<\/p>\n<p>Microsoft Scripting Guy Ed Wilson here. Things are pretty exciting around the Scripting House. It seems like the roofers are nearing completion of their project of repairing the storm damage we had, and our solar heater for the swimming pool is working out great. But the most exciting things are the summer speaking engagements I have coming up. The Scripting Wife and I are getting ready for my presentation to the Columbus Ohio Users Group meeting on Thursday, July 21. On Saturday, we will be in Wheeling West Virginia for SQL Saturday. Before that on July 20, I am speaking at the Virtual PowerShell group. On Sunday I head to Seattle where I will be speaking at the TechReady conference. Sound confusing? You can keep up with it all the same way I do: check out the <a href=\"http:\/\/technet.microsoft.com\/en-us\/scriptcenter\/hh182567\">Community Page<\/a> to see where you can catch the Scripting Guys either in person or at a virtual meeting.<\/p>\n<p>KF, because I am going to be spending so much time in front of the community in the next few weeks (I did not even mention the trip to Corpus Christy, Texas, or SQL Solstice in Raleigh), I thought it would be great to answer your question by using a community driven project. The <a href=\"http:\/\/pscx.codeplex.com\/\">PowerShell Community Extensions<\/a> (PSCX) project is a great example of community-driven modules. I have mentioned the <a href=\"http:\/\/blogs.technet.com\/search\/searchresults.aspx?q=pscx&amp;sections=7618\">PSCX previously<\/a>, and have even had a <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2010\/07\/09\/hey-scripting-guy-tell-me-about-powershell-community-extensions.aspx\">guest article written by Microsoft PowerShell MVP Keith Hill<\/a> that talked about the project.<\/p>\n<p>One thing to keep in mind is that by default, the user location for Windows PowerShell modules does not exist. That location can be in one or two places depending on the version of the operating system. On Windows Vista and later, it is in the Documents<i> <\/i>folder, but on Windows Server 2003 and before, it is in the My Documents<i> <\/i>folder. This is illustrated in the following lines of code:<\/p>\n<p style=\"padding-left: 30px\">$VistaPath = &#8220;$env:userProfile\\documents\\WindowsPowerShell\\Modules&#8221;<\/p>\n<p style=\"padding-left: 30px\">$XPPath =&nbsp; &#8220;$env:Userprofile\\my documents\\WindowsPowerShell\\Modules&#8221;<\/p>\n<p>&nbsp;<\/p>\n<p>The user location on a Windows 7 computer appears in the following figure. Keep in mind that the folder is not present because no user modules have been copied to this machine yet.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3250.HSG-7-18-11-01.png\"><img decoding=\"async\" style=\"border: 0px\" title=\"Image of user location on Windows 7 computer\" alt=\"Image of user location on Windows 7 computer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3250.HSG-7-18-11-01.png\" \/><\/a><\/p>\n<p>One thing that can be confusing is that by default, the <b>Get-ChildItem<\/b> cmdlet (<b>dir<\/b> is an alias) does not display hidden or system files. This can cause misleading results when Explorer is set to display hidden and system files, and the <i>force<\/i> parameter is not used. The two different views of the folder are shown here:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; dir $HOME\\documents&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; Directory: C:\\Users\\ed.IAMMRED\\documents<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\"><span style=\"text-decoration: underline\">Mode<\/span>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">LastWriteTime<\/span>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">Length Name<\/span><\/p>\n<p style=\"padding-left: 30px\">d&#8212;-&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7\/5\/2011&nbsp; 12:53 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SnagIt Catalog<\/p>\n<p style=\"padding-left: 30px\">d&#8212;-&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 6\/7\/2011&nbsp;&nbsp; 3:04 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Visual Studio 2010<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; dir $HOME\\documents -Force<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; Directory: C:\\Users\\ed.IAMMRED\\documents<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\"><span style=\"text-decoration: underline\">Mode<\/span>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">LastWriteTime<\/span>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">Length Name<\/span><\/p>\n<p style=\"padding-left: 30px\">d&mdash;hs&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7\/3\/2011&nbsp;&nbsp; 7:37 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; My Music<\/p>\n<p style=\"padding-left: 30px\">d&mdash;hs&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7\/3\/2011&nbsp;&nbsp; 7:37 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; My Pictures<\/p>\n<p style=\"padding-left: 30px\">d&mdash;hs&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7\/3\/2011&nbsp;&nbsp; 7:37 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; My Videos<\/p>\n<p style=\"padding-left: 30px\">d&#8212;-&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7\/5\/2011&nbsp; 12:53 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SnagIt Catalog<\/p>\n<p style=\"padding-left: 30px\">d&#8212;-&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 6\/7\/2011&nbsp;&nbsp; 3:04 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Visual Studio 2010<\/p>\n<p style=\"padding-left: 30px\">-a-h-&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7\/13\/2011&nbsp;&nbsp; 3:21 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1984 Default.rdp<\/p>\n<p style=\"padding-left: 30px\">-a-hs&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7\/3\/2011&nbsp;&nbsp; 7:37 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 402 desktop.ini<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt;<\/p>\n<p>As I mentioned in a previous article, my <b>Copy-Modules<\/b> script is not optimized to work with projects that include multiple types of files (such as .dll<i> <\/i>and<i> <\/i>.exe). I created it specifically to aid in the installation of simple module files. Therefore, my <b>Copy-Modules<\/b> script will not install the PSCX properly. However, a simple <b>Copy-Item<\/b> command will accomplish this (the following command is a single command; I added the backtick character to continue the command on the second line, but normally, you would not need to continue this command on a second line):<\/p>\n<p style=\"padding-left: 30px\">Copy-Item E:\\Downloads\\pscx -Destination `<\/p>\n<p style=\"padding-left: 30px\">$env:userProfile\\documents\\WindowsPowerShell\\Modules -recurse<\/p>\n<p>When installing the PSCX, keep in mind you need to unblock the .zip file that you download from CodePlex. <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2011\/04\/02\/scripting-wife-learns-about-unblocking-files-in-powershell.aspx\">This Scripting Wife article talks about unblocking files<\/a>. As a quick point of reference, a file downloaded from the Internet Zone is blocked from executing. In Windows 7, right-click the file, choose <b>Properties<\/b> from the shortcut menu, and click the <b>Unblock<\/b> button. The <b>Unblock<\/b> button is shown in the following figure.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6813.HSG-7-18-11-02.png\"><img decoding=\"async\" style=\"border: 0px\" title=\"Image of the Unblock button\" alt=\"Image of the Unblock button\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6813.HSG-7-18-11-02.png\" width=\"462\" height=\"648\" \/><\/a><\/p>\n<p>Speaking of unblocking files, the PSCX has the <b>Unblock-File<\/b> cmdlet. To use it, you provide a path to the file that needs to be unblocked, as shown here:<\/p>\n<p style=\"padding-left: 30px\">Unblock-File G:\\Pscx-2.0.0.1.zip<\/p>\n<p>When the above command runs, the <b>Unblock<\/b> button no longer appears on the <b>Properties<\/b> tab, as shown in the following figure.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5852.HSG-7-18-11-03.png\"><img decoding=\"async\" style=\"border: 0px\" title=\"Image of Unblock button no longer in Properties\" alt=\"Image of Unblock button no longer in Properties\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5852.HSG-7-18-11-03.png\" width=\"473\" height=\"654\" \/><\/a><\/p>\n<p>Of course, the <b>Unblock-File<\/b> cmdlet is not available until you install the PSCX. How did I find that command? After the module is installed, I use the <i>listavailable <\/i>switch from <b>Get-Module<\/b> to ensure it was installed properly. I then use the <b>Import-Module<\/b> cmdlet to import the module. Next, I use the <b>Get-Command<\/b> cmdlet with the <i>module <\/i>parameter. These three commands are shown here:<\/p>\n<p style=\"padding-left: 30px\">Get-Module &ndash;ListAvailable<\/p>\n<p style=\"padding-left: 30px\">Import-Module pscx<\/p>\n<p style=\"padding-left: 30px\">get-command -Module pscx<\/p>\n<p>&nbsp;After I have a feel for what a module offers, I might choose to only display the cmdlets:<\/p>\n<p style=\"padding-left: 30px\">get-command -Module pscx -CommandType cmdlet<\/p>\n<p>&nbsp;<\/p>\n<p>Why do I like PSCX so much? For one thing, it offers 87 cmdlets (I used the following command to find out that bit of trivia):<\/p>\n<p style=\"padding-left: 30px\">get-command -Module pscx -CommandType cmdlet | Measure-Object<\/p>\n<p>&nbsp;<\/p>\n<p>For another thing, the cmdlets are cool, and the project itself is a great model of community participation and cooperation to fill a real need.<\/p>\n<p>Anyway, KF, here are a couple of things I have found to be useful. One of the things I like to do is to generate a hash. The <b>Get-Hash<\/b> cmdlet is useful for doing such a thing. It will generate an error if you attempt to generate a hash of a directory, but you can get around that pretty easily by using a filter. The following command gets a directory listing, and filters all files (and folders) that do not match the <b>*.doc<\/b> filter. I then pipe those files to the <b>Get-Hash<\/b> cmdlet where a hash generates:<\/p>\n<p style=\"padding-left: 30px\">dir E:\\data\\ScriptingGuys -Filter *.doc | Get-Hash&nbsp;<\/p>\n<p>The command and associated output are shown in the following figure.<\/p>\n<p>&nbsp;<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6470.HSG-7-18-11-04.png\"><img decoding=\"async\" style=\"border: 0px\" title=\"Image of command and associated output\" alt=\"Image of command and associated output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6470.HSG-7-18-11-04.png\" \/><\/a><\/p>\n<p>But wait, there&rsquo;s more! I get tired of mousing around and copying stuff to the Clipboard, so I can paste it into Notepad. What if I pipe the results of the <b>Get-Hash<\/b> cmdlet to the <b>Set-Clipboard<\/b> cmdlet? While I am at it, why don&rsquo;t I go ahead and open Notepad so I can paste directly with Ctrl+V? Oh, yeah, that&rsquo;s the ticket. Here is the command:<\/p>\n<p style=\"padding-left: 30px\">dir E:\\data\\ScriptingGuys -Filter *.doc | Get-Hash | Out-Clipboard;notepad<\/p>\n<p>The following figure shows Notepad with the hash information pasted in it.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5672.HSG-7-18-11-05.png\"><img decoding=\"async\" style=\"border: 0px\" title=\"Image of Notepad with hash information\" alt=\"Image of Notepad with hash information\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5672.HSG-7-18-11-05.png\" \/><\/a>&nbsp;<\/p>\n<p>KF, that is all there is to using the PowerShell Community Extensions.&nbsp; Community Week will continue tomorrow when I will talk about more fun with community modules.<\/p>\n<p>&nbsp;<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Install the PSCX and get 80 new cmdlets to ease Windows PowerShell use. &nbsp; Hey, Scripting Guy! You have been spending quite a bit of time recently talking about functions and modules and the like. What is the big deal, and where would I find such modules? &mdash;KF &nbsp; Hello KF, Microsoft Scripting Guy [&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":[1],"tags":[52,3,4,45],"class_list":["post-13281","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-modules","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Install the PSCX and get 80 new cmdlets to ease Windows PowerShell use. &nbsp; Hey, Scripting Guy! You have been spending quite a bit of time recently talking about functions and modules and the like. What is the big deal, and where would I find such modules? &mdash;KF &nbsp; Hello KF, Microsoft Scripting Guy [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/13281","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=13281"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/13281\/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=13281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=13281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=13281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}