<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Hey, Scripting Guy! Blog</title><link>http://blogs.technet.com/b/heyscriptingguy/</link><description>The Hey, Scripting Guy! Blog is the number one blog hosting daily Windows PowerShell articles in a simple, scenario driven, how to format.</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>PowerTip: Find the Path to a PowerShell Module</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/18/powertip-find-the-path-to-a-powershell-module.aspx</link><pubDate>Sat, 18 May 2013 18:59:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3573399</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3573399</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/18/powertip-find-the-path-to-a-powershell-module.aspx#comments</comments><description>&lt;p&gt;&lt;strong style="font-size: 12px;"&gt;Summary&lt;/strong&gt;&lt;span style="font-size: 12px;"&gt;: Easily find the path to a Windows PowerShell module.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://img.microsoft.com/library/media/1033/technet/images/scriptcenter/qanda/q-sm.jpg" alt="Hey, Scripting Guy! Question" /&gt;&amp;nbsp;How can I easily find the path to a Windows PowerShell module?&lt;/p&gt;
&lt;p style="padding-left: 60px;"&gt;&lt;img src="http://img.microsoft.com/library/media/1033/technet/images/scriptcenter/qanda/a-sm.jpg" alt="Hey, Scripting Guy! Answer" /&gt;&amp;nbsp;Use the&amp;nbsp;&lt;strong&gt;Get-Module&lt;/strong&gt;&amp;nbsp;cmdlet and a wildcard character for the name, and select the &lt;strong&gt;Path&lt;/strong&gt; property. &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; The following script finds the PowerShellISEModule (an optional module in the Script Repository):&lt;/p&gt;
&lt;p style="padding-left: 150px;"&gt;(Get-Module -ListAvailable PowerShellIse*).path&lt;/p&gt;
&lt;p style="padding-left: 120px;"&gt;You can shorten the command:&lt;/p&gt;
&lt;p style="padding-left: 150px;"&gt;(gmo -l PowerShellIse*).path&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/7610.Dr.ScriptoForTips.jpg"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/150x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/7610.Dr.ScriptoForTips.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3573399" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Windows+PowerShell/">Windows PowerShell</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Scripting+Guy_2100_/">Scripting Guy!</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/PowerTip/">PowerTip</category></item><item><title>Weekend Scripter: Add Power and Functionality to the PowerShell ISE Part 1</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/18/weekend-scripter-add-power-and-functionality-to-the-powershell-ise.aspx</link><pubDate>Sat, 18 May 2013 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3573402</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3573402</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/18/weekend-scripter-add-power-and-functionality-to-the-powershell-ise.aspx#comments</comments><description>&lt;p&gt;&lt;strong style="font-size: 12px;"&gt;Summary&lt;/strong&gt;&lt;span style="font-size: 12px;"&gt;: Microsoft Scripting Guy, Ed Wilson, begins a revision of his Windows PowerShell ISE Module by adding five new functions.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. I decided to block off the weekend to work on my Windows PowerShell ISE module. There are several things that I want to add to it because the &amp;ldquo;annoyance&amp;rdquo; factor has finally caught up with me. In fact my criteria, when a repetitive task gets to the point that it annoys me, I will write a bit of code and solve the annoying problem. I have a list of five functions that I want to write and add to my Windows PowerShell ISE module. Here are the functions I want to add:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Add-RemarkedText&lt;/li&gt;
&lt;li&gt;Remove-MarkedText&lt;/li&gt;
&lt;li&gt;Edit-Module&lt;/li&gt;
&lt;li&gt;Import-EveryModule&lt;/li&gt;
&lt;li&gt;Switch-OutLineView&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So after I make a pot of Gunpowder Green Tea with jasmine, lemon grass, and a half spoonful of spearmint, I head back to my office, and my laptop is busy blaring &lt;a href="http://en.wikipedia.org/wiki/Willie_Nelson" target="_blank"&gt;Willie Nelson&lt;/a&gt;.&amp;nbsp; I look over at the Scripting Wife and say, &amp;ldquo;I thought I was playing &lt;a href="http://en.wikipedia.org/wiki/Mott_the_Hoople" target="_blank"&gt;Mott the Hoople&lt;/a&gt; when I left. What happened?&amp;rdquo;&lt;/p&gt;
&lt;p&gt;The Scripting Wife said, &amp;ldquo;You shouldn&amp;rsquo;t have left your computer unattended.&amp;rdquo; I guess she has a point, after all. Today I am going to talk about the first two functions: &lt;strong&gt;Add-RemarkedText&lt;/strong&gt; and &lt;strong&gt;Remove-MarkedText&lt;/strong&gt;. Tomorrow I will talk about the other three functions.&lt;/p&gt;
&lt;h2&gt;Comment (remark) out a block of selected script code&lt;/h2&gt;
&lt;p&gt;When I have a block of code that I want to comment (or remark) out, I generally use the Windows PowerShell&amp;nbsp;2.0 block quote feature of the &lt;strong&gt;&amp;lt;#&lt;/strong&gt; to open the comment and &lt;strong&gt;#&amp;gt;&lt;/strong&gt; to close the comment.&amp;nbsp; This technique is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;lt;#&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;"this is my code"&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;"that I want to comment (remark) out"&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;"for now"&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;#&amp;gt;&lt;/p&gt;
&lt;p&gt;The problem with this is that one way I troubleshoot my scripts is by commenting out sections of my code. In the Windows PowerShell ISE, I would like to be able to use the mouse (or keyboard shortcuts) to select a block of code and then to comment it out. Using the &lt;strong&gt;&amp;lt;# &lt;/strong&gt;and &lt;strong&gt;#&amp;gt;&lt;/strong&gt; seems to be a bit cumbersome for me.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;strong&gt;Note&lt;/strong&gt; &amp;nbsp;&amp;nbsp;If I am going to make major changes to a script, I use my &lt;strong&gt;Copy-ScriptToNewTab&lt;/strong&gt; function, which is already in my Windows PowerShell ISE module.&lt;/p&gt;
&lt;p&gt;My solution for this dilemma is my new &lt;strong&gt;Add-RemarkedText&lt;/strong&gt; function. To use it, I simply select a portion of the code in the current tab in the Windows PowerShell ISE, and in the command pane, I type &lt;strong&gt;Add-RemarkedText&lt;/strong&gt;. This is shown in the image that follows.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/2727.hsg_2D00_5_2D00_18_2D00_13_2D00_01.png"&gt;&lt;img title="Image of command output" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/2727.hsg_2D00_5_2D00_18_2D00_13_2D00_01.png" alt="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;When the &lt;strong&gt;Add-RemarkedText&lt;/strong&gt; function runs, the selected code is now commented (remarked) out, and it will not execute when the script runs. The commented section is shown in the image that follows.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/4064.hsg_2D00_5_2D00_18_2D00_13_2D00_02.png"&gt;&lt;img title="Image of command output" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/4064.hsg_2D00_5_2D00_18_2D00_13_2D00_02.png" alt="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Here is the complete &lt;strong&gt;Add-RemarkedText&lt;/strong&gt; function.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;strong&gt;ADD-RemarkedText function&lt;/strong&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Function Add-RemarkedText&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;{&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;lt;#&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp; .Synopsis&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; This function will add a remark # character to beginning of line&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp; .Description&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; This function will add a remark character # to selected text in the ISE.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; These are comment characters, and is great when you want to comment out&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; a section of PowerShell code.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp; .Example&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Add-RemarkedText&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; adds the comment / remark character to beginning of each selected line&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp; .Notes&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; NAME:&amp;nbsp; Add-RemarkedText&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; AUTHOR: ed wilson, msft&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; LASTEDIT: 05/16/2013&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; KEYWORDS: Windows PowerShell ISE, Scripting Techniques&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; HSG: wes-5-18-13&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp; .Link&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Http://www.ScriptingGuys.com&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;#Requires -Version 2.0&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;#&amp;gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;$text = $psISE.CurrentFile.editor.selectedText&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;foreach ($l in $text -split [environment]::newline)&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; {&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp; $newText += "{0}{1}" -f ("#" + $l),[environment]::newline&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp; $psISE.CurrentFile.Editor.InsertText($newText)&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;} #End function add-remarkedtext&lt;/p&gt;
&lt;h2&gt;Removing a commented section of code&lt;/h2&gt;
&lt;p&gt;After I have remarked out a portion of code, and I have completed my troubleshooting/testing scenario, it is time to remove the comments. In the past, this meant using the down arrow and the delete key, and hoping the mind numbing repetition did not lull me to sleep and cause me to delete a critical portion of the script.&lt;/p&gt;
&lt;p&gt;With my &lt;strong&gt;Remove-RemarkedText&lt;/strong&gt; function, this is no longer a problem. First I highlight (select) the commented out portion of the script, and then in the execution pane of the Windows PowerShell ISE, I type &lt;strong&gt;Remove-RemarkedText&lt;/strong&gt; (&lt;strong&gt;rr&lt;/strong&gt; is an alias). This technique is shown in the following image.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/6562.hsg_2D00_5_2D00_18_2D00_13_2D00_03.png"&gt;&lt;img title="Image of command output" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/6562.hsg_2D00_5_2D00_18_2D00_13_2D00_03.png" alt="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;When I press ENTER, the comment character (remarked out code) is removed as shown here:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8540.hsg_2D00_5_2D00_18_2D00_13_2D00_04.png"&gt;&lt;img title="Image of command output" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8540.hsg_2D00_5_2D00_18_2D00_13_2D00_04.png" alt="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Keep in mind that the code is still selected, and you should click away to remove the selection to protect yourself from accidently deleting the section of your script.&lt;/p&gt;
&lt;p&gt;Here is the complete text of the &lt;strong&gt;Remove-RemarkedText&lt;/strong&gt; function.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;strong&gt;Remove-RemarkedText&lt;/strong&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Function Remove-RemarkedText&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;{&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;lt;#&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp; .Synopsis&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; This function will remove a remark # character to beginning of line&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp; .Description&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; This function will remove a remark character # to selected text in the ISE.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; These are comment characters, and is great when you want to clean up a&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; previously commentted out section of PowerShell code.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp; .Example&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Remove-RemarkedText&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Removes the comment / remark character to beginning of each selected line&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp; .Notes&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; NAME:&amp;nbsp; Add-RemarkedText&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; AUTHOR: ed wilson, msft&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; LASTEDIT: 05/16/2013&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;KEYWORDS: Windows PowerShell ISE, Scripting Techniques&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; HSG: wes-5-18-13&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp; .Link&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Http://www.ScriptingGuys.com&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;#Requires -Version 2.0&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;#&amp;gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;$text = $psISE.CurrentFile.editor.selectedText&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;foreach ($l in $text -split [environment]::newline)&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; {&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; &amp;nbsp;$newText += "{0}{1}" -f ($l -replace '#',''),[environment]::newline&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp; $psISE.CurrentFile.Editor.InsertText($newText)&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;} #End function remove-remarkedtext&lt;/p&gt;
&lt;p&gt;Join me tomorrow when I will complete my discussion of the other three new ISE functions for my Windows PowerShell ISE module. Tomorrow I will also share the link to the Windows PowerShell ISE module project in the Scripting Guys Script Repository.&lt;/p&gt;
&lt;p&gt;I invite you to follow me on &lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt; and &lt;a href="http://bit.ly/scriptingguysfacebook" target="_blank"&gt;Facebook&lt;/a&gt;. If you have any questions, send email to me at &lt;a href="mailto:scripter@microsoft.com" target="_blank"&gt;scripter@microsoft.com&lt;/a&gt;, or post your questions on the &lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;. See you tomorrow. Until then, peace.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Ed Wilson, Microsoft Scripting Guy&lt;/strong&gt;&lt;span style="font-size: 12px;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3573402" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Windows+PowerShell/">Windows PowerShell</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Scripting+Guy_2100_/">Scripting Guy!</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/scripting+techniques/">scripting techniques</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Weekend+Scripter/">Weekend Scripter</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/modules/">modules</category></item><item><title>PowerTip: Use PowerShell to Get Virtual Machine Start Mode</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/17/powertip-use-powershell-to-get-virtual-machine-start-mode.aspx</link><pubDate>Fri, 17 May 2013 18:59:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3569979</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3569979</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/17/powertip-use-powershell-to-get-virtual-machine-start-mode.aspx#comments</comments><description>&lt;p&gt;&lt;strong style="font-size: 12px;"&gt;Summary&lt;/strong&gt;&lt;span style="font-size: 12px;"&gt;: Sean Kearney shows how to determine virtual machine start mode by using Windows PowerShell.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://img.microsoft.com/library/media/1033/technet/images/scriptcenter/qanda/q-sm.jpg" alt="Hey, Scripting Guy! Question" /&gt;&amp;nbsp;How can I tell which virtual machines will start automatically?&lt;/p&gt;
&lt;p style="padding-left: 60px;"&gt;&lt;img src="http://img.microsoft.com/library/media/1033/technet/images/scriptcenter/qanda/a-sm.jpg" alt="Hey, Scripting Guy! Answer" /&gt;&amp;nbsp;Use the&amp;nbsp;&lt;strong&gt;Get-VM&lt;/strong&gt;&amp;nbsp;cmdlet, and check the&amp;nbsp;&lt;strong&gt;AutomaticStartAction&lt;/strong&gt;&amp;nbsp;property:&lt;/p&gt;
&lt;p style="padding-left: 120px;"&gt;Get-VM | Format-Table Name,AutomaticStartAction -autosize&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/7610.Dr.ScriptoForTips.jpg"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/150x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/7610.Dr.ScriptoForTips.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3569979" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Windows+PowerShell/">Windows PowerShell</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Scripting+Guy_2100_/">Scripting Guy!</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/guest+blogger/">guest blogger</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Sean+Kearney/">Sean Kearney</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/PowerTip/">PowerTip</category></item><item><title>Change Virtual Machine Network Configuration with PowerShell</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/17/change-virtual-machine-network-configuration-with-powershell.aspx</link><pubDate>Fri, 17 May 2013 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3569980</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3569980</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/17/change-virtual-machine-network-configuration-with-powershell.aspx#comments</comments><description>&lt;p&gt;&lt;strong style="font-size: 12px;"&gt;Summary&lt;/strong&gt;&lt;span style="font-size: 12px;"&gt;: Learn how to use Windows PowerShell to change the virtual machine network configuration in Windows Server 2012.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. If you are a seasoned Hey, Scripting Guy! Blog reader, you know that the most frequent guest blogger is Sean Kearney. If you are new to the blog, I welcome you, and I encourage you to catch up with &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/tags/sean+kearney/" target="_blank"&gt;Sean&amp;rsquo;s previous blogs&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Sean is a Windows PowerShell MVP and &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/09/01/honorary-scripting-guy-award-recipients-announced.aspx" target="_blank"&gt;an Honorary Scripting Guy.&lt;/a&gt; Sean has been selected to present sessions called &lt;a href="http://channel9.msdn.com/Events/TechEd/NorthAmerica/2013/MDC-B326#fbid=rHDRO4Syj3v" target="_blank"&gt;Integrating with Microsoft System Center 2012 and Windows PowerShell&lt;/a&gt; at TechEd NA and TechEd Europe this year. In his free time, Sean has written several blog posts about Hyper-V and some other cool stuff, and for a few weeks, Sean will be the designated guest blogger on Fridays. Take it away Sean&amp;hellip;&lt;/p&gt;
&lt;p&gt;The other weekend I had a pile of virtual machines on our Windows Server 2012 with Hyper-V box. We had created a new network configuration with a &amp;ldquo;teamed lan&amp;rdquo; that we wanted to take advantage of.&lt;/p&gt;
&lt;p&gt;My co-worker and System Center mentor, Brad, looked over, &amp;ldquo;Sean, can you spend the afternoon and reconfigure the virtual machines to connect to the newly programmed Hyper-V network?&amp;rdquo;&lt;/p&gt;
&lt;p&gt;I stared at him as if he just gave birth to a bag of corn chips. &amp;ldquo;Huh? An hour? I&amp;rsquo;ll bet you that I can do it in less than five minutes!&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Knowing that I know Windows Powershell, Brad was intrigued, &amp;ldquo;Prove it!&amp;rdquo;&lt;/p&gt;
&lt;p&gt;I popped into the environment and ran the following cmdlet to see the names of the switches.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;GET-VMSWITCH&lt;/p&gt;
&lt;p&gt;This produced some useful output in the Windows Powershell console&amp;mdash;showing me all of the network switch names and configurations.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/2783.hsg_2D00_5_2D00_17_2D00_13_2D00_1.png"&gt;&lt;img style="border: 0px currentColor;" title="Image of command output" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/2783.hsg_2D00_5_2D00_17_2D00_13_2D00_1.png" alt="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now my challenge was to know which was the new and which was the old setup. I could look through the GUI console; but with Windows Powershell, I could have it tell me the same thing.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I pulled down the list of virtual machines with &lt;strong&gt;Get-VM&lt;/strong&gt; and used a new cmdlet from Hyper-V, &lt;strong&gt;Get-VMNetworkAdapter&lt;/strong&gt;. This cmdlet will show me the configuration of the network adapters within a virtual machine.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;GET-VM | GET-VMNetworkAdapter&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;By looking at the list, I could see the old switch configuration that I was using was named &amp;ldquo;Hyper-V-Lan1.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Making the change was so easy that my friend Brad&amp;rsquo;s eyes popped open just like Jim Carrey in &amp;ldquo;The Mask.&amp;rdquo; &amp;nbsp;I simply invoked another new built-in cmdlet, &lt;strong&gt;Connect-VMNetworkAdapter&lt;/strong&gt;. All I had to do was plug in the new network name I got from &lt;strong&gt;Get-VMSwitch&lt;/strong&gt;.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;GET-VM | GET-VMNetworkAdapter | Connect-VMNetworkAdapter &amp;ndash;Switchname &amp;lsquo;New-cool-Hyper-V-Lan&amp;rsquo;&lt;/p&gt;
&lt;p&gt;I looked up with a big goofy grin on my face, &amp;ldquo;Done! I&amp;rsquo;ll see you tomorrow.&amp;rdquo;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Brad blinked, &amp;ldquo;Tomorrow?&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;You just asked me to spend the afternoon. I did. I just spent it in a more efficient method!&amp;rdquo;&lt;/p&gt;
&lt;p&gt;The best part is knowing this: I could have just as easily switched the configuration on thousands of machines in a very similar time frame.&lt;/p&gt;
&lt;p&gt;Feel the Power within you.&lt;/p&gt;
&lt;p&gt;~Sean&lt;br /&gt; The Energized Tech&lt;/p&gt;
&lt;p&gt;Way cool stuff, Sean. Join Sean next week for more Windows PowerShell and Hyper-V stuff. Join me tomorrow for the Weekend Scripter.&lt;/p&gt;
&lt;p&gt;I invite you to follow me on &lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt; and &lt;a href="http://bit.ly/scriptingguysfacebook" target="_blank"&gt;Facebook&lt;/a&gt;. If you have any questions, send email to me at &lt;a href="mailto:scripter@microsoft.com" target="_blank"&gt;scripter@microsoft.com&lt;/a&gt;, or post your questions on the &lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;. See you tomorrow. Until then, peace.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Ed Wilson, Microsoft Scripting Guy&lt;/strong&gt;&lt;span style="font-size: 12px;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3569980" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Windows+PowerShell/">Windows PowerShell</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Scripting+Guy_2100_/">Scripting Guy!</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/servers/">servers</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/guest+blogger/">guest blogger</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Hyper_2D00_V/">Hyper-V</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Sean+Kearney/">Sean Kearney</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Windows+Server+2012/">Windows Server 2012</category></item><item><title>Scripting Wife Comments on Beginner Event 4</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/16/scripting-wife-comments-on-beginner-event-4.aspx</link><pubDate>Thu, 16 May 2013 18:59:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3569984</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3569984</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/16/scripting-wife-comments-on-beginner-event-4.aspx#comments</comments><description>&lt;p&gt;&lt;strong style="font-size: 12px;"&gt;Summary&lt;/strong&gt;&lt;span style="font-size: 12px;"&gt;: The Scripting Wife reveals her impressions of 2013 Scripting Games Beginner Event 4.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;When I first read this, I thought, &amp;ldquo;Dude, this is going to take an entire script.&amp;rdquo; But as I began to read the Help information for the&amp;nbsp;&lt;strong&gt;Get-Random&lt;/strong&gt;&amp;nbsp;cmdlet, it dawned on me that I could do this in a single line of code. It is really cool. I also used the cmdlets from the Active Directory module from the RSAT tools. In fact, if you want to brush up on that a bit, you may want to read my blog post,&amp;nbsp;&lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2013/04/23/use-the-ad-ds-module-to-find-computers-with-powershell.aspx" target="_blank"&gt;Use the AD DS Module to Find Computers with PowerShell&lt;/a&gt;. Although it is about computers, the process is the same with users. When I figured out how to get the random users, the rest was pretty simple. I used the AD&amp;nbsp;DS module, and I used the cmdlet I found last week when creating an HTML report. And that is all there is to it. Have fun!&lt;span style="font-size: 12px;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/7610.Dr.ScriptoForTips.jpg"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/150x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/7610.Dr.ScriptoForTips.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3569984" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Windows+PowerShell/">Windows PowerShell</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Scripting+Guy_2100_/">Scripting Guy!</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/PowerTip/">PowerTip</category></item><item><title>2013 Scripting Games: Advanced Event 4</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/16/2013-scripting-games-advanced-event-4.aspx</link><pubDate>Thu, 16 May 2013 07:03:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3569985</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3569985</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/16/2013-scripting-games-advanced-event-4.aspx#comments</comments><description>&lt;p align="left"&gt;&lt;span style="font-size: 12px;"&gt;&lt;strong&gt;Summary&lt;/strong&gt;: Scripting Games Advanced Event 4:&amp;nbsp;Dr. Scripto needs audit 20 random users from Active Directory.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. Once again it is time to reveal an event for the 2013 Scripting Games that are being hosted and run by&amp;nbsp;&lt;a href="http://www.powershell.org/" target="_blank"&gt;www.powershell.org&lt;/a&gt;. Head on over to their website to submit your entry.&lt;/p&gt;
&lt;h2&gt;An Auditing Adventure&lt;/h2&gt;
&lt;p&gt;Dr. Scripto isn&amp;rsquo;t saying he dislikes auditors, but they do seem to show up at the most inconvenient times&amp;mdash;and with the oddest requests. So he&amp;rsquo;s tossing this particular auditor request over to you.&lt;/p&gt;
&lt;p&gt;This auditor would like a report that shows 20 randomly selected (well, as random as you can get) users from Active Directory. For each user, the auditor wants to see their user name, their department and title, and the last time they logged on. You also need to show the date their password was last changed, and whether the account is disabled or locked out. So that&amp;rsquo;s seven pieces of information. You&amp;rsquo;re to put that information into an HTML-based report file, and the file must show the date and time that the report was generated. Please make sure that all of the dates are normal looking, human-readable dates and times.&lt;/p&gt;
&lt;p&gt;Auditors being like they are, the &amp;ldquo;20 randomly&amp;rdquo; selected number will probably change in the future, so you&amp;rsquo;d better build this as a reusable tool. Have a parameter that specifies the number of users to pull, and default it to 20. Also parameterize the output HTML file name. Oh, but if the specified file name doesn&amp;rsquo;t end in &amp;ldquo;.html&amp;rdquo; or &amp;ldquo;.htm,&amp;rdquo; reject it. Get Windows PowerShell to do as much of that validation as possible. Dr. Scripto has to review your code, and he doesn&amp;rsquo;t want to read a lot of manual validation script.&lt;/p&gt;
&lt;p&gt;A domain admin will always run the command (on behalf of the auditor), and the resulting HTML file will be manually emailed to the requesting auditor.&lt;/p&gt;
&lt;p&gt;I invite you to follow me on&amp;nbsp;&lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="http://bit.ly/scriptingguysfacebook" target="_blank"&gt;Facebook&lt;/a&gt;. If you have any questions, send email to me at&amp;nbsp;&lt;a href="mailto:scripter@microsoft.com" target="_blank"&gt;scripter@microsoft.com&lt;/a&gt;, or post your questions on the&amp;nbsp;&lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;. See you tomorrow. Until then, peace.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Ed Wilson, Microsoft Scripting Guy&lt;/strong&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3569985" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Windows+PowerShell/">Windows PowerShell</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Scripting+Guy_2100_/">Scripting Guy!</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Advanced/">Advanced</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Event+4/">Event 4</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/2013+Scripting+Games/">2013 Scripting Games</category></item><item><title>2013 Scripting Games: Beginner Event 4</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/16/2013-scripting-games-beginner-event-4.aspx</link><pubDate>Thu, 16 May 2013 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3569986</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3569986</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/16/2013-scripting-games-beginner-event-4.aspx#comments</comments><description>&lt;p&gt;&lt;strong style="font-size: 12px;"&gt;Summary&lt;/strong&gt;&lt;span style="font-size: 12px;"&gt;: Scripting Games Beginner Event 4:&amp;nbsp;Dr. Scripto needs to audit 20 random users from Active Directory.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. Once again it is time to reveal an event for the 2013 Scripting Games that are being hosted and run by &lt;a href="http://www.powershell.org/" target="_blank"&gt;www.powershell.org&lt;/a&gt;. Head on over to their website to submit your entry.&lt;/p&gt;
&lt;h2&gt;An Auditing Adventure&lt;/h2&gt;
&lt;p&gt;&lt;span style="font-size: 12px;"&gt;Dr. Scripto isn&amp;rsquo;t saying that he dislikes auditors, but they do seem to show up at the most inconvenient times&amp;mdash;and with the oddest requests. So he&amp;rsquo;s tossing this particular auditor request over to you.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;This auditor would like a report that shows 20 randomly selected (well, as random as you can get) users from Active Directory. For each user, the auditor wants to see their user name, their department and title, and the last time they logged on. You also need to show the date their password was last changed, and whether the account is disabled or locked out. So that&amp;rsquo;s seven pieces of information. You&amp;rsquo;re to put that information into an HTML-based report file, and the file must show the date and time that the report was generated. Please make sure that all of the dates are normal looking, human-readable dates and times.&lt;/p&gt;
&lt;p&gt;Keep your command as concise as possible, although that doesn&amp;rsquo;t mean you&amp;rsquo;re not allowed to use full command and parameter names&amp;mdash;that&amp;rsquo;s always okay to do! A domain admin will always run the command, and the resulting HTML file will be manually emailed to the requesting auditor.&lt;/p&gt;
&lt;p&gt;I invite you to follow me on &lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt; and &lt;a href="http://bit.ly/scriptingguysfacebook" target="_blank"&gt;Facebook&lt;/a&gt;. If you have any questions, send email to me at &lt;a href="mailto:scripter@microsoft.com" target="_blank"&gt;scripter@microsoft.com&lt;/a&gt;, or post your questions on the &lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;. See you tomorrow. Until then, peace.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Ed Wilson, Microsoft Scripting Guy&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Windows PowerShell, Scripting Guy!, 2013 Scripting Games, Event 4, Beginner&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3569986" width="1" height="1"&gt;</description></item><item><title>PowerTip: Find All Required Assemblies for PowerShell Modules</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/15/powertip-find-all-required-assemblies-for-powershell-modules.aspx</link><pubDate>Wed, 15 May 2013 18:59:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3572608</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3572608</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/15/powertip-find-all-required-assemblies-for-powershell-modules.aspx#comments</comments><description>&lt;p&gt;&lt;strong style="font-size: 12px;"&gt;Summary&lt;/strong&gt;&lt;span style="font-size: 12px;"&gt;: Find required assemblies for your Windows PowerShell modules.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://img.microsoft.com/library/media/1033/technet/images/scriptcenter/qanda/q-sm.jpg" alt="Hey, Scripting Guy! Question" /&gt;&amp;nbsp;How can I use Windows PowerShell to show required assemblies for my Windows PowerShell modules?&lt;/p&gt;
&lt;p style="padding-left: 60px;"&gt;&lt;img src="http://img.microsoft.com/library/media/1033/technet/images/scriptcenter/qanda/a-sm.jpg" alt="Hey, Scripting Guy! Answer" /&gt;&amp;nbsp;Use the&amp;nbsp;&lt;strong&gt;ExpandProperty&lt;/strong&gt;&lt;em&gt;&amp;nbsp;&lt;/em&gt;parameter of&amp;nbsp;&lt;strong&gt;Select-Object&lt;/strong&gt;&amp;nbsp;and choose the&amp;nbsp;&lt;strong&gt;RequiredAssemblies&lt;/strong&gt;&lt;em&gt;&amp;nbsp;&lt;/em&gt;property from the&amp;nbsp;&lt;strong&gt;Get-Module&lt;/strong&gt;&amp;nbsp;cmdlet after you have imported all Windows PowerShell modules:&lt;/p&gt;
&lt;p style="padding-left: 150px;"&gt;Get-Module -ListAvailable | Import-Module&lt;/p&gt;
&lt;p style="padding-left: 150px;"&gt;Get-Module | Select-Object -ExpandProperty requiredassemblies&lt;/p&gt;
&lt;p style="padding-left: 120px;"&gt;By using aliases, this command shortens to:&lt;/p&gt;
&lt;p style="padding-left: 150px;"&gt;gmo -l | ipmo&lt;/p&gt;
&lt;p style="padding-left: 150px;"&gt;gmo | select -Expand requiredassemblies&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/7610.Dr.ScriptoForTips.jpg"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/150x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/7610.Dr.ScriptoForTips.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3572608" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Windows+PowerShell/">Windows PowerShell</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Scripting+Guy_2100_/">Scripting Guy!</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/PowerTip/">PowerTip</category></item><item><title>I Found This Module—What Do I Do?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/15/i-found-this-module-what-do-i-do.aspx</link><pubDate>Wed, 15 May 2013 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3572613</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3572613</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/15/i-found-this-module-what-do-i-do.aspx#comments</comments><description>&lt;p&gt;&lt;strong style="font-size: 12px;"&gt;Summary&lt;/strong&gt;&lt;span style="font-size: 12px;"&gt;: Microsoft Scripting Guy, Ed Wilson, talks about how to use a Windows PowerShell module.&lt;/span&gt;&lt;span style="font-size: 12px;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://img.microsoft.com/library/media/1033/technet/images/scriptcenter/qanda/q-sm.jpg" alt="Hey, Scripting Guy! Question" /&gt;&amp;nbsp;Hey, Scripting Guy! &amp;nbsp;I found this module in the Scripting Guys Script Repository. Now what do I do?&lt;/p&gt;
&lt;p&gt;&amp;mdash;SH&lt;/p&gt;
&lt;p&gt;&lt;img src="http://img.microsoft.com/library/media/1033/technet/images/scriptcenter/qanda/a-sm.jpg" alt="Hey, Scripting Guy! Answer" /&gt;&amp;nbsp;Hello SH,&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. This morning I have been busy booking travel to &lt;a href="http://europe.msteched.com/#fbid=Y6s0qEgGIo3" target="_blank"&gt;Madrid, Spain for TechEd 2013&lt;/a&gt;. I will have a booth there with the Scripting Wife. In addition, I will be joining the Windows PowerShell team for their instructor led lab&amp;mdash;it will be way cool. Air travel these days is so much fun, I genuinely look forward to each upcoming flight. This includes my flight to &lt;a href="http://northamerica.msteched.com/#fbid=fii1JDbUFpU" target="_blank"&gt;TechEd 2013 in New Orleans&lt;/a&gt;, where you can also find the Scripting Wife and me. (I am also conducting a Windows PowerShell instructor led lab in the &lt;a href="http://en.wikipedia.org/wiki/New_Orleans" target="_blank"&gt;big easy&lt;/a&gt;.)&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;strong&gt;Note&amp;nbsp;&amp;nbsp;&lt;/strong&gt;This is the fourth part of a multipart series about using Windows PowerShell functions and modules. Prior to reading this blog, you should read the previous posts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/08/i-found-this-powershell-function-now-what-do-i-do.aspx" target="_blank"&gt;I Found this PowerShell Function&amp;mdash;Now What Do I Do? Part 1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/13/i-found-this-powershell-function-now-what-do-i-do-part-2.aspx" target="_blank"&gt;I Found this PowerShell Function&amp;mdash;Now What Do I Do? Part 2&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/14/i-found-this-powershell-function-now-what-do-i-do-part-3.aspx" target="_blank"&gt;I Found this PowerShell Function&amp;mdash;Now What Do I Do? Part 3&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;What do I do with a module I find?&lt;/h2&gt;
&lt;p&gt;Let us suppose that I find a module such as the &lt;a href="http://gallery.technet.microsoft.com/scriptcenter/2d191bcd-3308-4edd-9de2-88dff796b0bc" target="_blank"&gt;Windows Update PowerShell Module&lt;/a&gt; in the Scripting Guys Script Repository. What do I do with it? Well, the first thing I need to do is to download and to install the module. But this is where things are actually a bit confusing. This is because I can put the module anywhere I want to put it. One of the great things about Windows PowerShell modules is that no installer is required. Most modules, in fact, use a simple copy and paste type of installation (the so-called XCOPY deployment, but you do not need to use XCOPY if you do not wish to do so).&lt;/p&gt;
&lt;h2&gt;Where do I put the module?&lt;/h2&gt;
&lt;p&gt;There are two places I can put modules so that Windows PowerShell will automatically recognize them, and will automatically import them. These locations are stored in the &lt;strong&gt;PSModulePath &lt;/strong&gt;environmental variable&lt;em&gt;. &lt;/em&gt;From a basic categorization standpoint, one is in my profile/home directory, and the other one is in System32. This output on my computer is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; $env:PSModulePath -split ";"&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;C:\Users\ed.IAMMRED\Documents\WindowsPowerShell\Modules&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;C:\Windows\system32\WindowsPowerShell\v1.0\Modules\&lt;/p&gt;
&lt;p&gt;It requires admin rights to copy something into the System32 folder, and that is where people sometimes place modules that require admin rights. The problem with this location is that when Windows undergoes servicing, it remotes items from the system folders that it does not know about. This means that your admin&lt;em&gt; &lt;/em&gt;type of modules can easily become deleted the next time you run Windows update or apply a service pack.&lt;/p&gt;
&lt;p&gt;The problem with storing all modules in my profile/home directory location occurs if I am running as a normal user, and then I need to elevate to an account with admin rights so I can run a module that requires admin rights. My profile/home directory is now a NEW location because I am running as a different user. This makes it painful to navigate back to the old user profile location to launch the module manually.&lt;/p&gt;
&lt;p&gt;The answer is simple. Modify the &lt;strong&gt;$env:PSModulePath&lt;/strong&gt; location to include an additional folder&amp;mdash;either one on a network, or a folder in an easily accessible location. For example, I have a central data&lt;em&gt; &lt;/em&gt;folder that I use to simplify backups (an XCOPY backup, so to speak). I could easily create a central modules folder that is accessible for all users on the computer. This technique is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; $env:PSModulePath = $env:PSModulePath + ';c:\data\modules'&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; $env:PSModulePath -split ";"&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;C:\Users\ed.IAMMRED\Documents\WindowsPowerShell\Modules&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;C:\Windows\system32\WindowsPowerShell\v1.0\Modules\&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;c:\data\modules&lt;/p&gt;
&lt;h2&gt;How do I put the module in its location?&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s go back to the &lt;em&gt;Windows Update PowerShell Module &lt;/em&gt;from the Scripting Guys Script Repository. It is contained in a file called PSWindowsUpdate.zip. I click the PSWindowsUpdate.zip file in the Script Repository, and after I agree to the terms of use, Internet Explorer asks if I want to Open, Save, or Cancel my action. This is shown in the image that follows.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/5736.hsg_2D00_5_2D00_15_2D00_13_2D00_01.png"&gt;&lt;img title="Image of menu" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/5736.hsg_2D00_5_2D00_15_2D00_13_2D00_01.png" alt="Image of menu" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If I select Open, the zipped file opens revealing a subfolder as shown here:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/2677.hsg_2D00_5_2D00_15_2D00_13_2D00_02.png"&gt;&lt;img title="Image of menu" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/2677.hsg_2D00_5_2D00_15_2D00_13_2D00_02.png" alt="Image of menu" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Cool, it seems that all I need to do is to open my module directory and drag the folder from the zipped folder to my module home directory. The problem if I do this is the files in the folder will all be blocked.&amp;nbsp; This is shown in the following image.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/4718.hsg_2D00_5_2D00_15_2D00_13_2D00_03.png"&gt;&lt;img title="Image of menu" src="http://blogs.technet.com/resized-image.ashx/__size/350x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/4718.hsg_2D00_5_2D00_15_2D00_13_2D00_03.png" alt="Image of menu" width="350" height="480" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I can use Windows PowerShell&amp;nbsp;3.0 to unblock the files, but it is easier to unblock the files before installation. To do this, save the .zip file, then right-click it to unblock the file prior to extraction. In this way, all the files contained therein are unblocked. However, if I forget to do this, I can use a command such as the following to unblock the files:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\Users\ed.IAMMRED\Documents\WindowsPowerShell\Modules&amp;gt; gci .\PSWindowsUpdate -Re&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;curse | Unblock-File&lt;/p&gt;
&lt;p&gt;After I copy the unzipped and unblocked Windows PowerShell module files to the module directory, I can import the module and use the cmdlets. Because I am dealing with Windows update, the Windows PowerShell console needs to be elevated. The following error appears if the Windows PowerShell console is not elevated.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/0181.hsg_2D00_5_2D00_15_2D00_13_2D00_04.png"&gt;&lt;img title="Image of error message" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/0181.hsg_2D00_5_2D00_15_2D00_13_2D00_04.png" alt="Image of error message" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;After I elevate Windows PowerShell, I use the &lt;strong&gt;Import-Module&lt;/strong&gt; cmdlet to import the module, and I use the &lt;strong&gt;Get-Command&lt;/strong&gt; cmdlet to see what commands are exposed by the module. This is shown here.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/6014.hsg_2D00_5_2D00_15_2D00_13_2D00_05.png"&gt;&lt;img title="Image of command output" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/6014.hsg_2D00_5_2D00_15_2D00_13_2D00_05.png" alt="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now that I see the commands, I can use them just like any other Windows PowerShell command from any other module. So I can check to see what updates are available via the &lt;strong&gt;Get-WUList&lt;/strong&gt; cmdlet (function) as shown here:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; Get-WUList&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;ComputerName Status KB&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;Size Title&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;------------ ------ --&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ---- -----&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;EDLT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ---H-- KB2694771&amp;nbsp;&amp;nbsp; 5 MB Bing Desktop v1.2&lt;/p&gt;
&lt;p&gt;To install an update, I use the &lt;strong&gt;Get-WUInstall&lt;/strong&gt; function, and to hide an update I use the &lt;strong&gt;Hide-WUUpdate&lt;/strong&gt; command. Pipeline support is available.&lt;/p&gt;
&lt;p&gt;I can even check to see if a reboot is required as shown here:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; Get-WURebootStatus&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Reboot is not Required.&lt;/p&gt;
&lt;p&gt;SH, that is all there is to using a Windows PowerShell module.&amp;nbsp; Join me tomorrow when I will reveal the 2013 Scripting Games Event 4.&lt;/p&gt;
&lt;p&gt;I invite you to follow me on &lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt; and &lt;a href="http://bit.ly/scriptingguysfacebook" target="_blank"&gt;Facebook&lt;/a&gt;. If you have any questions, send email to me at &lt;a href="mailto:scripter@microsoft.com" target="_blank"&gt;scripter@microsoft.com&lt;/a&gt;, or post your questions on the &lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;. See you tomorrow. Until then, peace.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Ed Wilson, Microsoft Scripting Guy&lt;/strong&gt;&lt;span style="font-size: 12px;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3572613" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Windows+PowerShell/">Windows PowerShell</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Scripting+Guy_2100_/">Scripting Guy!</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/scripting+techniques/">scripting techniques</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/modules/">modules</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/functions/">functions</category></item><item><title>PowerTip: Use PowerShell to Show Screensaver Info for Logged-on User</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/14/powertip-use-powershell-to-show-screensaver-info-for-logged-on-user.aspx</link><pubDate>Tue, 14 May 2013 18:59:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3572368</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3572368</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/14/powertip-use-powershell-to-show-screensaver-info-for-logged-on-user.aspx#comments</comments><description>&lt;p&gt;&lt;strong style="font-size: 12px;"&gt;Summary&lt;/strong&gt;&lt;span style="font-size: 12px;"&gt;: Use Windows PowerShell to show screensaver info for a user who is logged on.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://img.microsoft.com/library/media/1033/technet/images/scriptcenter/qanda/q-sm.jpg" alt="Hey, Scripting Guy! Question" /&gt;&amp;nbsp;How can I easily use Windows PowerShell to show screensaver information for the currently logged-on interactive user?&lt;/p&gt;
&lt;p style="padding-left: 60px;"&gt;&lt;img src="http://img.microsoft.com/library/media/1033/technet/images/scriptcenter/qanda/a-sm.jpg" alt="Hey, Scripting Guy! Answer" /&gt;&amp;nbsp;Use WMI to query the Win32_Desktop class, and filter on the logged-on user&amp;rsquo;s name:&lt;/p&gt;
&lt;p style="padding-left: 120px;"&gt;Get-Wmiobject win32_desktop | where name -match $env:USERNAME&lt;/p&gt;
&lt;p align="left"&gt;&amp;nbsp;&lt;a style="font-size: 12px;" href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/7610.Dr.ScriptoForTips.jpg"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/150x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/7610.Dr.ScriptoForTips.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3572368" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Windows+PowerShell/">Windows PowerShell</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Scripting+Guy_2100_/">Scripting Guy!</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/PowerTip/">PowerTip</category></item></channel></rss>