<?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 includes helpful how-to posts and scripts about VBScript, PowerShell, Active Directory, and other Microsoft technologies.</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>Use PowerShell to Perform Offline Analysis of Security Logs</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/29/use-powershell-to-perform-offline-analysis-of-security-logs.aspx</link><pubDate>Tue, 29 May 2012 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3499918</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=3499918</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/29/use-powershell-to-perform-offline-analysis-of-security-logs.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Microsoft Scripting Guy, Ed Wilson, discusses using Windows PowerShell to dump and to analyze event logs&amp;mdash;including security logs.&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! I often need to process Windows event logs when I am called to do a forensic investigation of a server. One of the problems with saving the event log so that I can look at it later is that I end up with a log that is pretty well useless because I do not have the required application DLLs installed on my computer. Is there a way that Windows PowerShell can help me do this without me having to install a bunch of admin tools on my laptop?&lt;/p&gt;
&lt;p&gt;&amp;mdash;RG&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; Hello RG,&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. I have been preparing my presentations for the &lt;a href="http://www.cmschill.net/StringTheory/uncategorized/announcing-atlanta-techstravaganza-2012/" target="_blank"&gt;Atlanta TechStravaganza&lt;/a&gt;, which happens this Friday June 1, 2012 at the Microsoft Office in Alpharetta. The Scripting Wife is busy getting ready&amp;mdash;she made an appointment at the spa for a pedicure, manicure, and massage. I think she is going to the spa with a group of her friends, and they may be going out for lunch and shopping afterwards. I am always a bit leery when shopping trips involve stopping for meals. For me a shopping trip generally involves about five minutes online (unless it is going to a computer super store&amp;hellip;but that is different).&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Note&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;This is the second in a series of four Hey, Scripting Guy! blogs about using Windows PowerShell to facilitate security forensic analysis of a compromised computer system. The intent of the series is not to teach security forensics, but rather to illustrate how Windows PowerShell could be utilized to assist in such an inquiry. The first blog discussed &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/28/use-powershell-to-aid-in-security-forensics.aspx" target="_blank"&gt;using Windows PowerShell to capture and to analyze process and service information&lt;/a&gt;.&lt;/p&gt;
&lt;h1&gt;First, dump the event logs&lt;/h1&gt;
&lt;p&gt;The first thing to do if you plan to perform detailed analysis of the security logs, is to dump them into a format that facilitates later processing with Windows PowerShell.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Note&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If you save the event log as an EVTX type of file, when you open it back up in the Event Viewer utility tool, your machine may require certain DLL files to provide the replacement strings for the various events. These DLL files are typically installed with the various management utilities that come with certain applications.&lt;/p&gt;
&lt;p&gt;To dump the event log, you can use the &lt;b&gt;Get-EventLog&lt;/b&gt; and the &lt;b&gt;Exportto-Clixml&lt;/b&gt; cmdlets if you are working with a traditional event log such as the Security, Application, or System event logs. If you need to work with one of the trace logs, use the &lt;b&gt;Get-WinEvent&lt;/b&gt; and the &lt;b&gt;ExportTo-Clixml&lt;/b&gt; cmdlets.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Note&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; For more information about working with event logs, review this collection of blogs about &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/tags/windows+powershell/event+logs/" target="_blank"&gt;using Windows PowerShell to work with event logs&lt;/a&gt; because there is some great information. Two great blogs to begin with are:&lt;/p&gt;
&lt;ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2009/04/06/how-can-i-check-my-event-logs.aspx" target="_blank"&gt;How Can I Check My Event Logs?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2010/04/21/hey-scripting-guy-april-21-2010.aspx" target="_blank"&gt;The Scripting Wife Uses Windows PowerShell to Read from the Windows Event Log&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;p&gt;To dump all of the events in the Application log to an XML file that is stored on a network share, use the following syntax:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-EventLog -LogName application | Export-Clixml \\hyperv1\shared\Forensics\edApplog.xml&lt;/p&gt;
&lt;p&gt;If you want to dump the System, Application, and Security logs into XML files on a network share, use the following syntax.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Note&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; The &lt;b&gt;%&lt;/b&gt; symbol is an alias for the &lt;b&gt;Foreach-Object&lt;/b&gt; cmdlet. It is often used when working interactively from the Windows PowerShell console, although its use in a script would not necessarily be appropriate. For more information, read &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/05/01/best-practice-for-using-aliases-in-powershell-scripts.aspx" target="_blank"&gt;Best Practice for Using Aliases in PowerShell Scripts&lt;/a&gt;.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$logs = "system","application","security"&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$logs | % { get-eventlog -LogName $_ | Export-Clixml "\\hyperv1\shared\Forensics\$_.xml" }&lt;/p&gt;
&lt;p&gt;The previous commands, which retrieve the three classic event logs and export them in XML format to a network share, and the associated output (no output) are 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/6038.hsg_2D00_5_2D00_29_2D00_12_2D00_02.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/6038.hsg_2D00_5_2D00_29_2D00_12_2D00_02.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;Second, import the event log of interest&lt;/h1&gt;
&lt;p&gt;To parse the event logs, use the &lt;b&gt;Import-Clixml&lt;/b&gt; cmdlet to read the stored XML files from your shared network location. Store the results in a variable. Next, you can use any of the normal Windows PowerShell cmdlets you would use when parsing event logs (&lt;b&gt;Where-Object&lt;/b&gt;, &lt;b&gt;Group-Object&lt;/b&gt;, and &lt;b&gt;Select-Object&lt;/b&gt; are three of the main cmdlets that I use). The following two commands first read the exported security log contents into a variable named &lt;b&gt;$seclog&lt;/b&gt;, and then the five oldest entries are obtained.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$seclog = Import-Clixml \\hyperv1\shared\Forensics\security.xml&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$seclog | select -Last 5&lt;/p&gt;
&lt;p&gt;One thing you must keep in mind is that once you export the security log to XML, it is no longer protected by anything more than the NFTS and share permissions that are assigned to the location where you store everything. By default, an ordinary user does not have permission to read the security log. As seen in the previous image, when you start the Windows PowerShell console as an administrator, all event logs are dumpable.&lt;/p&gt;
&lt;p&gt;The following image illustrates this situation. In a Windows PowerShell console launched as a normal non-elevated user, the command to read the Security event log fails with an access denied error message. The next command reads the security event log from the stored XML, stores the resulting event log into a variable, and then displays the five oldest entries from the log.&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/4478.hsg_2D00_5_2D00_29_2D00_12_2D00_03.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/4478.hsg_2D00_5_2D00_29_2D00_12_2D00_03.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It is, therefore, imperative that the appropriate NTFS permissions and share permissions level protect the offline versions of these event logs.&lt;/p&gt;
&lt;h2&gt;Drill into a specific entry with Format-List&lt;/h2&gt;
&lt;p&gt;To view the entire contents of a specific event log entry, choose that entry, send the results to the &lt;b&gt;Format-List&lt;/b&gt; cmdlet, and choose all of the properties. This technique is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$seclog | select -first 1 | fl *&lt;/p&gt;
&lt;p&gt;The contents of a specific event log entry varies, depending on the provider. The following audit entry details the special privileges that are assigned to a new login. (Interestingly enough, this specific entry was the result of opening the Windows PowerShell console with administrative rights.)&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/8867.hsg_2D00_5_2D00_29_2D00_12_2D00_04.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8867.hsg_2D00_5_2D00_29_2D00_12_2D00_04.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The message property contains the SID, account name, user domain, and privileges that are assigned for the new login. This property is a string, and therefore, it can be parsed by using normal string techniques. The image that follows illustrates obtaining only the &lt;b&gt;message&lt;/b&gt; property from the newest event log entry, and using the &lt;b&gt;gettype &lt;/b&gt;method to determine the exact data type. These are the two commands that I used:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;($seclog | select -first 1).message&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;(($seclog | select -first 1).message).gettype()&lt;/p&gt;
&lt;p&gt;The commands and the output associated with the commands are 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/5873.hsg_2D00_5_2D00_29_2D00_12_2D00_05.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/5873.hsg_2D00_5_2D00_29_2D00_12_2D00_05.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;At times, you merely need to do a bit of analysis work: How often is the &lt;b&gt;SeSecurityPrivilege&lt;/b&gt; privilege mentioned in the &lt;b&gt;message&lt;/b&gt;&lt;i&gt; &lt;/i&gt;property? To obtain this information, pipe the contents of the security log to a &lt;b&gt;Where-Object&lt;/b&gt; to filter the events, and then send the results to the &lt;b&gt;Measure-Object&lt;/b&gt; cmdlet to determine the number of events, as shown here:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$seclog | ? { $_.message -match 'SeSecurityPrivilege'} | measure&lt;/p&gt;
&lt;p&gt;If you want to ensure that only event log entries return that contain &lt;b&gt;SeSecurityPrivilege&lt;/b&gt; in their text, use &lt;b&gt;Group-Object&lt;/b&gt; to gather the matches by the &lt;b&gt;EventID&lt;/b&gt; property. The command that does this is shown here:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$seclog | ? { $_.message -match 'SeSecurityPrivilege'} | group eventid&lt;/p&gt;
&lt;p&gt;Because importing the event log into a variable from the stored XML results in a collection of event log entries, it means that the &lt;b&gt;count&lt;/b&gt;&lt;i&gt; &lt;/i&gt;property is also present. Use the &lt;b&gt;count&lt;/b&gt;&lt;i&gt; &lt;/i&gt;property to determine the total number of entries in the event log as shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$seclog.Count&lt;/p&gt;
&lt;p&gt;The use of these three commands and the output associated 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/8055.hsg_2D00_5_2D00_29_2D00_12_2D00_06.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8055.hsg_2D00_5_2D00_29_2D00_12_2D00_06.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Dig into the logs with Windows PowerShell standard techniques&lt;/h2&gt;
&lt;p&gt;I like to examine an event log for event distribution. This answers the question, &amp;ldquo;What is causing all of these events?&amp;rdquo; And it provides a direction for further analysis. The easy way to do this is to use the &lt;b&gt;Group-Object&lt;/b&gt; cmdlet and the &lt;b&gt;Sort-Object&lt;/b&gt; cmdlet. The use of these two cmdlets is shown here (remember that the variable &lt;b&gt;$seclog&lt;/b&gt; contains the offline security log that we dumped at the beginning of this blog, and after storing the log in XML format, we reconstituted it by using the &lt;b&gt;Import-CliXml&lt;/b&gt; cmdlet). When I am merely attempting to get an idea of event distribution, I use the &lt;i&gt;NoElement &lt;/i&gt;switch, which removes the grouping information from the output.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$seclog | group eventid -NoElement | sort count&lt;/p&gt;
&lt;p&gt;The command to group the security events by event ID, and the results from the command are 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/1212.hsg_2D00_5_2D00_29_2D00_12_2D00_07.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/1212.hsg_2D00_5_2D00_29_2D00_12_2D00_07.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Interestingly enough, this image tells me that there are 2280 events with the event ID of 4672. But of those 2280 events, we know that only 1925 entries include &lt;b&gt;SeSecurityPrivilege&lt;/b&gt; being granted. What does all this mean? Who knows, but at least with Windows PowerShell you have the tools at your fingertips to surface this information and you have your experience as an IT Pro to draw your own conclusions.&lt;/p&gt;
&lt;p&gt;RG, that is all there is to using Windows PowerShell to dump event logs and to perform offline analysis. Security Week will continue tomorrow when I will talk about MD5 hash analysis of files and folders.&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;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&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=3499918" 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/security/">security</category></item><item><title>Use PowerShell to Aid in Security Forensics</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/28/use-powershell-to-aid-in-security-forensics.aspx</link><pubDate>Mon, 28 May 2012 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3499905</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3499905</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/28/use-powershell-to-aid-in-security-forensics.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Microsoft Scripting Guy, Ed Wilson, discusses using Windows PowerShell to aid in security forensic analysis of processes and services on a compromised system.&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! It seems that somewhere I read that you have your CISSP certification, so I expect that you know about security. I am wondering, do you know anything about using Windows PowerShell for forensic analysis of potentially compromised servers?&lt;/p&gt;
&lt;p&gt;&amp;mdash;RM&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 RM,&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. Today is a holiday in the United States, so I decided to celebrate by getting up early and checking the email sent to &lt;a href="mailto:scripter@microsoft.com"&gt;scripter@microsoft.com&lt;/a&gt;. The Scripting Wife is also up (it is always a little eerie when she is up before noon on her day off). I have no idea what she is up to, but she did volunteer to make a pot of tea for me. She mixed up a bit of English Breakfast tea, a half spoon of organic hibiscus flower, and a half spoon of lemon grass. She topped it off with a cinnamon stick. I have to say she did an excellent job. If you are anywhere near Atlanta, you should definitely make plans to attend the &lt;a href="http://www.cmschill.net/StringTheory/uncategorized/announcing-atlanta-techstravaganza-2012/" target="_blank"&gt;Atlanta TechStravaganza&lt;/a&gt;. I am making two presentations, and there is an entire Windows PowerShell track (the Scripting Wife will be there too). One thing that is unique this year (although they did it during the &lt;a href="http://www.sqlsaturday.com/111/eventhome.aspx" target="_blank"&gt;SQL Saturday in Atlanta&lt;/a&gt;) is Hal Rottenberg and Jon Walz will record the &lt;a href="http://powerscripting.wordpress.com/" target="_blank"&gt;PowerScripting Podcast&lt;/a&gt; live during the last session of the day. As shown in the photo that follows, we had a TON of fun during SQL Saturday, and the session during the Atlanta TechStravaganza should be no different.&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/4380.HSG_2D00_5_2D00_28_2D00_12_2D00_1.jpg"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/400x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/4380.HSG_2D00_5_2D00_28_2D00_12_2D00_1.jpg" alt="Photo" title="Photo" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;PowerShell is PowerShell is PowerShell&lt;/h1&gt;
&lt;p&gt;RM, the key thing to remember, whether you are doing security forensics, Exchange Server administration, Office automation, or anything between, is that Windows PowerShell is Windows PowerShell is Windows PowerShell. This means that all of the Windows PowerShell best practices still apply. One of those Windows PowerShell best practices is to preserve the object. The object-oriented nature of Windows PowerShell is one of the revolutionary features of the language, and it is a major contributor to its ease-of-use.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Note&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/b&gt;When doing any type of computer forensics, a major principle is to avoid making any changes to the system. Therefore, as a crucial first step, you should use a tool such as the Windows Sysinternals utility tool, &lt;a href="http://technet.microsoft.com/en-us/sysinternals/ee656415" target="_blank"&gt;Disk2vhd&lt;/a&gt;, so you can be assured of not changing things like file access times on the original system.&lt;/p&gt;
&lt;p&gt;Therefore, in keeping with the object-oriented nature of Windows PowerShell, you want to use techniques that preserve the object for as long as possible.&lt;/p&gt;
&lt;h1&gt;Preserving process and service objects&lt;/h1&gt;
&lt;p&gt;I feel a bit sad when I see people saving process or service information to a text file, and then watch as they create a hundred-line script that invokes various complex regular expressions to parse each file as they attempt to compare two files to pull out information. With security work, what you accomplish prior to a problem arising determines what you can do after the problem manifests itself. For example, if you have obtained periodic baselines, you have a great reference for comparison as you attempt to discover the differences between your pristine system and the compromised machine with which you now work. If you do not have a baseline, the next best thing is to build a duplicate system (hopefully from some backup device), and use that as your reference point.&lt;/p&gt;
&lt;p&gt;So what am I talking about? Well, remember that you want to preserve objects so further analysis is easy. The best way to preserve process objects and service objects is to export them to XML. The following two commands export process and service information to an XML format (and thus preserve their object-oriented nature). The commands take a few seconds to work because the file is stored on a network file share.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-Process | Export-Clixml -Path \\hyperv1\shared\forensics\EDPROC.XML&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-Service | Export-Clixml -Path \\hyperv1\shared\forensics\EDService.XML&lt;/p&gt;
&lt;h1&gt;Comparing process and service information&lt;/h1&gt;
&lt;p&gt;In doing security forensics, it is typical to want to compare one &amp;ldquo;snapshot&amp;rdquo; with another &amp;ldquo;snapshot.&amp;rdquo; What you need to do is to compare the baseline (or what you are using for your baseline) with the information that is gathered from the compromised system. The following command reads the baseline of process information into a variable, and it also reads the delta snapshot into a variable. Next, it uses &lt;b&gt;Compare-Object&lt;/b&gt; to find the difference between the two process snapshots.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$edproc = Import-Clixml -Path \\hyperv1\shared\Forensics\EDPROC.XML&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$edproc1 = Import-Clixml -Path \\hyperv1\shared\Forensics\EDPROC1.XML&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Compare-Object $edproc $edproc1 -Property processname&lt;/p&gt;
&lt;p&gt;The commands and the output associated with running the three commands are 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/2768.hsg_2D00_5_2D00_28_2D00_12_2D00_02.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/2768.hsg_2D00_5_2D00_28_2D00_12_2D00_02.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you only need to determine the number of changes between the baseline and the delta snapshot, pipe the results to the &lt;b&gt;Group-Object&lt;/b&gt; cmdlet. This technique is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; Compare-Object $edproc $edproc1 -Property processname | group sideindicator&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Count Name&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Group&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2 =&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {@{processname=notepad; SideIndicator==&amp;gt;}, @{proc...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 &amp;lt;=&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {@{processname=audiodg; SideIndicator=&amp;lt;=}}&lt;/p&gt;
&lt;p&gt;Because you are working with rich objects (not mere text), the normal properties of the object continue to exist.&lt;/p&gt;
&lt;p&gt;To drill in on one of the newly created processes, pipe the variable that contains the new process to the &lt;b&gt;Where-Object&lt;/b&gt;, and pick it out of the collection. To view all of the information about the process, send the results to the &lt;b&gt;Format-List&lt;/b&gt; cmdlet. That command is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$edproc1 | where { $_.processname -eq 'notepad'} | fl *&lt;/p&gt;
&lt;p&gt;This technique is illustrated 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/1212.hsg_2D00_5_2D00_28_2D00_12_2D00_03.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/1212.hsg_2D00_5_2D00_28_2D00_12_2D00_03.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;A number of properties from the process object appear to merit additional investigation. Some of the properties that interest me are &lt;b&gt;StartTime&lt;/b&gt;, &lt;b&gt;PrivilegedProcessorTime&lt;/b&gt;, &lt;b&gt;Path&lt;/b&gt;, &lt;b&gt;FileVersion&lt;/b&gt;, and the memory information.&lt;/p&gt;
&lt;p&gt;Some of the properties contain other objects, such as the &lt;b&gt;Threads&lt;/b&gt; property. To examine that more fully, store resultant object in a variable, and then drill down into it. This technique is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$notepad = $edproc1 | where { $_.processname -eq 'notepad'}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$notepad.Threads&lt;/p&gt;
&lt;p&gt;The commands and the associated output from the commands are 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/4152.hsg_2D00_5_2D00_28_2D00_12_2D00_04.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/4152.hsg_2D00_5_2D00_28_2D00_12_2D00_04.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Use the same technique to compare your service information.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Note&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;When you take your snapshots (either the baseline or the delta), ensure that you use administrative rights. This is because some information is not available to a non-privileged account.&lt;/p&gt;
&lt;p&gt;RM, that is all there is to using Windows PowerShell to compare service and process information. Security Week will continue tomorrow when I will talk about using Windows PowerShell to analyze Security event logs.&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;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&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=3499905" 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/security/">security</category></item><item><title>Weekend Scripter: Use PowerShell to Manage Your Windows Azure Deployments</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/27/weekend-scripter-use-powershell-to-manage-your-windows-azure-deployments.aspx</link><pubDate>Sun, 27 May 2012 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3499881</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=3499881</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/27/weekend-scripter-use-powershell-to-manage-your-windows-azure-deployments.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Guest blogger, Microsoft evangelist Brian Hitney, discusses using Windows PowerShell to create and to manage Windows Azure deployments.&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. Today we have guest blogger, Brian Hitney. Brian is a developer evangelist at Microsoft. You can read more by Brian in his blog, &lt;a href="http://structuretoobig.com/" target="_blank"&gt;Structure Too Big Blog: Developing on the Microsoft Stack&lt;/a&gt;.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Hi everyone, Brian Hitney here. I&amp;rsquo;m a developer evangelist at Microsoft, and I focus on Windows Azure. Recently, I was asked to give a presentation to the &lt;a href="http://powershellgroup.org/charlotte.nc" target="_blank"&gt;Windows PowerShell User Group in Charlotte, North Carolina&lt;/a&gt; about managing Windows Azure deployments with Windows PowerShell. I have not done too much work with Windows PowerShell and Windows Azure, so this was a perfect opportunity to learn!&lt;/p&gt;
&lt;h1&gt;Getting started with Windows Azure&lt;/h1&gt;
&lt;p&gt;To begin, let us briefly talk about Windows Azure. Windows Azure is the cloud computing platform by Microsoft. It is comprised of a number of offerings and services, the most obvious being application and virtual machine hosting. There are also storage facilities to store tabular data, binary objects such as documents, images, and so on. Of course, it includes SQL Azure, which is a fully managed, redundant SQL Server instance. &amp;nbsp;What makes cloud computing so attractive is that it scales based on your needs. You can run a small website easily in an extra small instance (2 cents/hour, or about $15.00/month), or you can hit a button to scale out to dozens of 8 CPU servers. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now that we know what it is, you will need an account. If you have a MSDN subscription, you are already there and you have &lt;a href="http://www.windowsazure.com/en-us/pricing/member-offers/msdn-benefits/" target="_blank"&gt;some great benefits&lt;/a&gt; as part of your subscription. If not, you are still in luck because you can use Azure for &lt;a href="http://www.microsoft.com/click/services/Redirect2.ashx?CR_CC=200082763" target="_blank"&gt;free for 90 days&lt;/a&gt;. &amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Note&lt;/b&gt;: Oh, and a shameless plug: If you want to learn about the cloud and would like a fun activity to do in the process, check out our &lt;a href="http://distributedcomputing.cloudapp.net/" target="_blank"&gt;@home with Windows Azure project&lt;/a&gt; or &lt;a href="http://www.rockpaperazure.com/" target="_blank"&gt;RockPaperAzure&lt;/a&gt;. Both are designed to be fun, hands-on exercises.&lt;/p&gt;
&lt;p&gt;Now that we know what Windows Azure is and how to get an account, let&amp;rsquo;s talk about the portal. The current version of the &lt;a href="http://windows.azure.com/" target="_blank"&gt;Windows Azure Platform&lt;/a&gt; is Silverlight based, and you would typically upload your files, create new hosted services, and so on, directly through this portal. An application consists of two files: a package file (.cspkg) and a configuration file (.cscfg), usually created from within Visual Studio. As a platform-as-a-service, Windows Azure manages the operating system, IIS, and patches automatically. In the following portal screenshot, you will see I have a number of subscriptions, and within my MSDN subscription, I have two hosted services. You cannot tell from the screenshot without looking at the properties, but the top service (in the red box) is located in the North Central datacenter, and the bottom service (still coming online) is in the West Europe datacenter. There are four datacenters in North America, two in Europe, and two in Asia.&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/8461.wes_2D00_5_2D00_27_2D00_12_2D00_1.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8461.wes_2D00_5_2D00_27_2D00_12_2D00_1.png" alt="Image of menu" title="Image of menu" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;Adding Windows PowerShell to the mixture&lt;/h1&gt;
&lt;p&gt;Phew! We are finally ready to talk scripting! In addition to the portal, Windows Azure offers a REST-style management API that we can leverage (it is secured with X.509 certificates). Writing against this directly, while not impossible, is not a very fun task. Fortunately, there are &lt;a href="http://wappowershell.codeplex.com/" target="_blank"&gt;Windows Azure PowerShell Cmdlets&lt;/a&gt; on CodePlex that wrap the complexity into simple to use cmdlets for creating and managing our Azure services.&lt;/p&gt;
&lt;h2&gt;Set up the project and upload certificate&lt;/h2&gt;
&lt;p&gt;The first step is to upload an X.509 certificate to the Windows Azure Management Portal. In a typical enterprise or managed environment, certificate requests would be managed through a central IT department with an internal certification authority (CA). For individual use, it&amp;rsquo;s simply easiest to create self-signed certificates. There is a lot of documentation about the various ways to do this, so we won&amp;rsquo;t go into that here. Check out &lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/gg551722.aspx" target="_blank"&gt;How to Create a Management Certificate for Windows Azure&lt;/a&gt; or &lt;a href="http://wappowershell.codeplex.com/documentation" target="_blank"&gt;Windows Azure PowerShell Cmdlets&lt;/a&gt; for more information about creating a management certificate.&lt;/p&gt;
&lt;p&gt;Developers will typically be working with Visual Studio, and there are a number of project templates for cloud applications. The templates make it easy to build a cloud app from the ground up, but it&amp;rsquo;s also easy to create an empty cloud project, and bring preexisting websites and applications into the cloud project. In many cases, little or no code change is necessary to an ASP.NET-driven website. To download the SDK for Visual Studio, or to check out the other toolkits available, visit &lt;a href="http://www.windowsazure.com/en-us/develop/downloads/" target="_blank"&gt;Windows Azure Downloads&lt;/a&gt;. As mentioned previously, a Windows Azure application will compile to two files, a package file and a configuration file. For sake of convenience, they are attached at the end of this blog in a zip file. They can also easily be created in Visual Studio by right-clicking the Solution Explorer and selecting &lt;b&gt;Package&lt;/b&gt; as 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/4137.wes_2D00_5_2D00_27_2D00_12_2D00_2.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/400x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/4137.wes_2D00_5_2D00_27_2D00_12_2D00_2.png" alt="Image of menu" title="Image of menu" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Setting up a new hosted service&lt;/h2&gt;
&lt;p&gt;In this demo, we will set up a new hosted service by using Windows PowerShell. In fact, we&amp;rsquo;ll do this in two separate datacenters (North Central and West Europe). We&amp;rsquo;ll also create a storage account for each application that is in the same datacenter. It&amp;rsquo;s typically a best practice to have at least one storage account in each datacenter where an application is hosted for performance and reduced bandwidth charges.&lt;/p&gt;
&lt;h3&gt;Set up the variables&lt;/h3&gt;
&lt;p&gt;To begin, we will set up some variables for our script:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Import-Module WAPPSCmdlets&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$subid = "{your subscription id}"&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$cert = Get-Item cert:\CurrentUser\My\01784B3F26B609044A56AC5B1CFEF287321420F5&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$storageaccount = "somedemoaccount"&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$storagekey = "{your key}"&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$servicename_nc = "bhitneypowershellNC"&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$servicename_we = "bhitneypowershellWE"&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$storagename_nc = "bhitneystoragenc"&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$storagename_we = "bhitneystoragewe"&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$globaldns = "bhitneyglobal"&lt;/p&gt;
&lt;p&gt;Your subscription ID can be obtained from the portal by clicking your account (shown earlier in the green box in the dashboard). You can obtain the thumbprint of a management certificate directly from your local certificate store (or by examining the file, if not in the local store). Or as shown here, you can look at the thumbprint in the portal by clicking &lt;b&gt;Management Certificates&lt;/b&gt; and looking at the properties after you select the certificate:&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/6724.wes_2D00_5_2D00_27_2D00_12_2D00_3.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/300x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/6724.wes_2D00_5_2D00_27_2D00_12_2D00_3.png" alt="Image of menu" title="Image of menu" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In the following image, the &lt;i&gt;somedemoaccount&lt;/i&gt; storage account is my &amp;ldquo;master storage account.&amp;rdquo; It&amp;rsquo;s where I&amp;rsquo;ll dump my diagnostics data (more on that in another blog post) and all of my global data that isn&amp;rsquo;t specific to a single deployment. Every storage account has a name (for example, &lt;i&gt;somedemoaccount&lt;/i&gt;) and two access keys, which can be obtained from the dashboard also.&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/1055.wes_2D00_5_2D00_27_2D00_12_2D00_4.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/1055.wes_2D00_5_2D00_27_2D00_12_2D00_4.png" alt="Image of menu" title="Image of menu" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;However, we will actually be creating storage accounts in script, too.&lt;/p&gt;
&lt;p&gt;The &lt;b&gt;$servicename&lt;/b&gt; variables are simply DNS names that will be created for our deployment. When they are deployed, the North Central deployment will have an addressable URL as bhitneypowershellNC.cloudapp.net, and the West Europe URL will be bhitneypowershellWE.cloudapp.net.&lt;/p&gt;
&lt;p&gt;The &lt;b&gt;$storagename&lt;/b&gt; variables are the names of the storage accounts we&amp;rsquo;ll be creating for these deployments. Although not completely necessary in this context, I&amp;rsquo;m including this primarily as an example.&lt;/p&gt;
&lt;h3&gt;Persist your profile information&lt;/h3&gt;
&lt;p&gt;One of the neat things you can do with the Windows Azure PowerShell cmdlets is save the subscription and related profile information into a setting that can be persisted for other scripts:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;# Persisting Subscription Settings&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Set-Subscription -SubscriptionName powershelldemo -Certificate $cert -SubscriptionId $subid&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;# Setting default Subscription&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Set-Subscription -DefaultSubscription powershelldemo&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;# Setting the current subscription to use&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Select-Subscription -SubscriptionName powershelldemo&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;# Save the cert and subscription id for subscriptions&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Set-Subscription -SubscriptionName powershelldemo -StorageAccountName $storageaccount -StorageAccountKey $storagekey&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;# Specify the default storage account to use for the subscription&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Set-Subscription -SubscriptionName powershelldemo -DefaultStorageAccount $storageaccount&lt;/p&gt;
&lt;p&gt;This means that we don&amp;rsquo;t have to constantly define the certificate thumbprint, keys, subscription IDs, and so on. They can be recalled by using &lt;b&gt;Select-Subscription&lt;/b&gt;. This will make writing future scripts easier, and the settings can be updated in one place instead of having to modify every script that uses these settings.&lt;/p&gt;
&lt;h3&gt;Set up the storage account and hosted service&lt;/h3&gt;
&lt;p&gt;Now let&amp;rsquo;s set up the storage account and hosted service:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;# Configure North Central location&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;New-StorageAccount -ServiceName $storagename_nc -Location "North Central US"&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; | Get-OperationStatus &amp;ndash;WaitToComplete&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;New-HostedService -ServiceName $servicename_nc -Location "North Central US" | Get-OperationStatus &amp;ndash;WaitToComplete&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;New-Deployment -serviceName $servicename_nc &amp;ndash;StorageAccountName $storagename_nc `&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;&amp;nbsp;&amp;nbsp; -Label MySite `&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;&amp;nbsp;&amp;nbsp; -slot staging -package "D:\powershell\package\PowerShellDemoSite.cspkg" &amp;ndash;configuration "D:\powershell\package\ServiceConfiguration.Cloud.cscfg" | Get-OperationStatus -WaitToComplete&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-Deployment -serviceName $servicename_nc -Slot staging `&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;&amp;nbsp;&amp;nbsp; | Set-DeploymentStatus -Status Running | Get-OperationStatus -WaitToComplete&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Move-Deployment -DeploymentNameInProduction $servicename_nc -ServiceName $servicename_nc -Name MySite&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;re creating a new storage account, and because the operation is asynchronous, we&amp;rsquo;ll pipe &lt;b&gt;Get-OperationStatus &amp;ndash;WaitToComplete&lt;/b&gt; to have the script wait until the operation is done before continuing. &amp;nbsp;Next, we will create the hosted service. The hosted service is the container and the DNS name for our application. When this is done, the service is created; however, nothing is yet deployed. Think of it as a reservation.&lt;/p&gt;
&lt;h3&gt;Deploy the code&lt;/h3&gt;
&lt;p&gt;We will deploy the code by using the &lt;b&gt;New-Deployment&lt;/b&gt; command. In this case, we&amp;rsquo;ll deploy the service (note the paths to package files) to the staging slot with a simple label of &lt;b&gt;MySite&lt;/b&gt;. Each hosted service has a staging and production slot. Staging is billed and treated the same as production, but staging is given a temporary URL to be used as a smoke test prior to going live.&lt;/p&gt;
&lt;p&gt;By default, the service is deployed, but in the stopped state, so we&amp;rsquo;ll set the status to running with the &lt;b&gt;Set-DeploymentStatus&lt;/b&gt; command. When it is running, we&amp;rsquo;ll move it from staging to production with the &lt;b&gt;Move-Deployment&lt;/b&gt; command. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;ll also repeat the same thing for our West Europe deployment. Let&amp;rsquo;s say, though, that we&amp;rsquo;d like to programmatically increase the number of instances of our application. That&amp;rsquo;s easy enough to do:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;#Increase the number of instances to 2&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-HostedService -ServiceName $servicename_nc | `&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Get-Deployment -Slot Production | `&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set-RoleInstanceCount -Count 2 -RoleName "WebRole1"&lt;/p&gt;
&lt;p&gt;This is a huge benefit of scripting! Imagine being able to scale an application programmatically either to a set schedule (Monday-Friday, or perhaps during the holiday or tax seasons), or based on criteria such as performance counters or site load.&lt;/p&gt;
&lt;p&gt;When we have more than one instance of an application in a given datacenter, Windows Azure will automatically load balance incoming requests to those instances. But let&amp;rsquo;s set up a profile by using the Windows Azure Traffic Manager to globally load balance.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;# Set up a geo-loadbalance between the two using the Traffic Manager&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$profile = New-TrafficManagerProfile -ProfileName bhitneyps `&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;-DomainName ($globaldns + ".trafficmanager.net")&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$endpoints = @()&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$endpoints += New-TrafficManagerEndpoint -DomainName ($servicename_we + ".cloudapp.net")&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$endpoints += New-TrafficManagerEndpoint -DomainName ($servicename_nc + ".cloudapp.net")&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;# Configure the endpoint Traffic Manager will monitor for service health&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$monitors = @()&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$monitors += New-TrafficManagerMonitor &amp;ndash;Port 80 &amp;ndash;Protocol HTTP &amp;ndash;RelativePath /&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;# Create new definition&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$createdDefinition = New-TrafficManagerDefinition -ProfileName bhitneyps -TimeToLiveInSeconds 300 `&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -LoadBalancingMethod Performance -Monitors $monitors -Endpoints $endpoints -Status Enabled&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;# Enable the profile with the newly created traffic manager definition&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Set-TrafficManagerProfile -ProfileName bhitneyps -Enable -DefinitionVersion $createdDefinition.Version&lt;/p&gt;
&lt;p&gt;This is more straightforward than it might seem. First we are creating a profile, which is essentially asking what global DNS name we would like to use. We can CNAME our own DNS name (such as www.mydomain.com) if we&amp;rsquo;d like, but the profile will have a *.trafficmanager.net name. Next we are setting up endpoints. In this case, we are telling it to use both the North Central and West Europe deployments as endpoints. &amp;nbsp;&lt;/p&gt;
&lt;h3&gt;Set up the monitor&lt;/h3&gt;
&lt;p&gt;Next, we will set up a monitor. In this case, the Traffic Manager will watch Port 80 of the deployments, requesting the root (&amp;ldquo;/&amp;rdquo;) document. This is equivalent to a simple HTTP GET of the webpage, but it opens up possibilities for custom monitoring pages. If these requests generate an error response, the Traffic Manager will stop sending traffic to that location.&lt;/p&gt;
&lt;p&gt;When it is complete, we can browse to this application by going to &amp;ldquo;bhitneyglobal.trafficmanager.net.&amp;rdquo; There you have it&amp;mdash;from nothing to a geo-load-balanced, redundant, scalable application in a few lines of script!&lt;/p&gt;
&lt;p&gt;Now let&amp;rsquo;s tear it all down!&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;# Cleanup&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Remove-TrafficManagerProfile bhitneyps | Get-OperationStatus -WaitToComplete&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Remove-Deployment -Slot production -serviceName $servicename_nc&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Remove-Deployment -Slot production -serviceName $servicename_we | Get-OperationStatus -WaitToComplete&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Remove-HostedService -serviceName $servicename_nc&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Remove-HostedService -serviceName $servicename_we | Get-OperationStatus -WaitToComplete&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Remove-StorageAccount -StorageAccountName $storagename_nc&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Remove-StorageAccount -StorageAccountName $storagename_we | Get-OperationStatus &amp;ndash;WaitToComplete&lt;/p&gt;
&lt;p&gt;The &lt;a href="http://gallery.technet.microsoft.com/scriptcenter/Managing-Windows-Azure-9dc7d6b3" target="_blank"&gt;full script and zip download&lt;/a&gt; can be found in the Script Repository.&lt;/p&gt;
&lt;p&gt;Happy scripting!&lt;/p&gt;
&lt;p&gt;~Brian&lt;/p&gt;
&lt;p&gt;Thank you, Brian, for sharing your time and knowledge. This is an awesome introduction to an exciting new technology.&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;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&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=3499881" 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/guest+blogger/">guest blogger</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Azure/">Azure</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Brian+Hitney/">Brian Hitney</category></item><item><title>Weekend Scripter: The Mission for “True-Up” Data Via Get-WmiObject</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/26/weekend-scripter-the-mission-for-true-up-data-via-get-wmiobject.aspx</link><pubDate>Sat, 26 May 2012 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3499277</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=3499277</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/26/weekend-scripter-the-mission-for-true-up-data-via-get-wmiobject.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Guest blogger, Brian Wilhite, shares his experience using Windows PowerShell jobs to speed up collecting information from WMI.&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. This weekend, we will start with guest blogger, Brian Wilhite.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Brian Wilhite works as a Windows system administrator for a large health-care provider in North Carolina. He has over 15 years of experience in IT. In his current capacity as a Windows system administrator, he leads a team of individuals who have responsibilities for Microsoft Exchange Server, Windows Server builds, and management and system performance. Brian also supports and participates in the &lt;a href="http://powershellgroup.org/charlotte.nc" target="_blank"&gt;Charlotte PowerShell Users Group&lt;/a&gt;. &lt;br /&gt; Twitter: &lt;a href="http://twitter.com/bwilhite1979" target="_blank"&gt;Brian Wilhite&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Take it away Brian&amp;hellip;&lt;/p&gt;
&lt;p&gt;Here in North Carolina, it&amp;rsquo;s getting warmer, the rain is falling, flowers are blooming, and nature is giving us a blast of pollen to last a lifetime&amp;mdash;yes, spring is in full swing. Like most things that are common with this time of year, so is my organization&amp;rsquo;s Microsoft Enterprise Agreement &amp;ldquo;True-Up.&amp;rdquo; If you are like us, we gather information from various data sources, such as SCCM, Active Directory and/or a CMDB. I was on a mission, given to me by my manager, to track down all Windows Server installations in my organization&amp;rsquo;s domain. I began by querying Active Directory for computer objects that have a server operating system by using the Active Directory module in Windows PowerShell. To import the Active Directory module, I will have to, &lt;i&gt;you guessed it&lt;/i&gt;, use &lt;b&gt;Import-Module&lt;/b&gt;. It looks like this:&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/6710.Fig1.JPG"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/6710.Fig1.JPG" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Note&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Prior to running this cmdlet, to ensure that you have the Active Directory module available for import, you can run the following Windows PowerShell code:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Get-Module - ListAvailable&lt;/p&gt;
&lt;p&gt;If you do not have the Active Directory module available, you need to download and install the&lt;b&gt; &lt;/b&gt;&lt;a href="http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&amp;amp;id=7887" target="_blank"&gt;Remote Server Administration Tools&lt;/a&gt;&lt;b&gt; &lt;/b&gt;from the Microsoft Download Center. In addition, for them to work on any domain earlier than Windows Server&amp;nbsp;2008, you need to install &lt;a href="http://blogs.msdn.com/b/adpowershell/archive/2009/09/18/active-directory-management-gateway-service-released-to-web-manage-your-windows-2003-2008-dcs-using-ad-powershell.aspx" target="_blank"&gt;Active Directory Management Gateway Service&lt;/a&gt;.&lt;b&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Next, I use &lt;b&gt;Get-ADComputer&lt;/b&gt; to query Active Directory for all computer objects that have &amp;ldquo;Server&amp;rdquo; in the &lt;b&gt;OperatingSystem&lt;/b&gt; property, and I stored it as &lt;b&gt;$AllServers&lt;/b&gt;. I also wanted to export this to a CSV file for review. Notice that I use the &lt;i&gt;NoTypeInformation&lt;/i&gt; parameter. In my opinion, this should be the default; however, this parameter will not display the object data at the top of the CSV.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$AllServers = Get-ADComputer -Filter {OperatingSystem -like "*Server*"} -Properties OperatingSystem | Select Name, OperatingSystem&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$AllServers | Export-Csv -Path C:\Users\Brian\Desktop\AllServers.csv -NoTypeInformation&lt;/p&gt;
&lt;p&gt;When reviewing the data shown in the following image, I realized that Windows Server&amp;nbsp;2008 populates the Standard, Enterprise, and Datacenter versions correctly within Active Directory. However, Windows Server&amp;nbsp;2003 does not:&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/3808.wes_2D00_5_2D00_26_2D00_12_2D00_2.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/350x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3808.wes_2D00_5_2D00_26_2D00_12_2D00_2.png" alt="Image of menu" title="Image of menu" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Because the &amp;ldquo;True-Up&amp;rdquo; requires us to count what specific versions we&amp;rsquo;re running, I need to go one step further to gather that information. When I thought about how I was going to gather this data, I pondered for a bit, and then I decided that I would use my good old friend WMI. Because I already had the counts for the servers running Windows Server&amp;nbsp;2008, and I had the data filtering in Excel, I would shift my focus and effort to the servers running Windows Server&amp;nbsp;2003. To isolate them from the &lt;b&gt;$AllServers&lt;/b&gt; variable that I created earlier, I ran the following code, selecting only the &lt;b&gt;Name&lt;/b&gt; property:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$2003ServersOnly = $AllServers | Where-Object {$_.OperatingSystem -eq &amp;ldquo;Windows Server 2003&amp;rdquo;} | Select -ExpandProperty Name&lt;/p&gt;
&lt;p&gt;Now that I had all the names of servers running Windows Server&amp;nbsp;2003 in a variable to itself, I ran the following code &amp;ldquo;trying&amp;rdquo; to export the data to a CSV file:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-WmiObject -Class Win32_OperatingSystem -ComputerName $2003ServersOnly | Select CSName, Caption | Export-Csv -Path C:\Users\Brian\Desktop\2003Servers.csv -NoTypeInformation&lt;/p&gt;
&lt;p&gt;This should work because the &lt;i&gt;ComputerName&lt;/i&gt; parameter will accept an array of computer names. It is also quicker than piping to a &lt;b&gt;Foreach-Object&lt;/b&gt;. However, about 20 minutes later, I noticed that the CSV file was not growing in size like it had earlier, so I terminated the one-liner. I gave it more thought, and I decided that I would try the &lt;b&gt;Foreach-Object&lt;/b&gt; route to see where that would take me. That code follows:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$2003ServersOnly | ForEach-Object {Get-WmiObject -Class Win32_OperatingSystem -ComputerName $_} | Select CSName, Caption | Export-Csv -Path C:\Users\Brian\Desktop\2003Servers.csv -NoTypeInformation&lt;/p&gt;
&lt;p&gt;That didn&amp;rsquo;t work either. About 20 minutes later, I noticed that it stalled once again. Back to the drawing board&amp;hellip;&lt;/p&gt;
&lt;p&gt;I gave it further thought, and I remembered a conversation that I had with a good friend of mine about the &lt;b&gt;AsJob&lt;/b&gt; parameter for &lt;b&gt;Get-WmiObject&lt;/b&gt;. It came about because of a function I wrote, &lt;a href="http://gallery.technet.microsoft.com/scriptcenter/Get-ComputerInfo-Query-23dd6042"&gt;Get-ComputerInfo&lt;/a&gt;, which serially queries a set of 8 or 9 WMI classes. He said that he made some modifications specifically around running &lt;b&gt;Get-WmiObject -AsJob&lt;/b&gt;, so that the queries would run asynchronously, making the function execute faster. So I put that method into practice for the mission at hand. Instead of running the objects one at a time through the pipeline, why not create a job for each server and see if my one-liner continues to stall? Boy, was I in for a surprise on this one. I ran the following code:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$2003ServersOnly | ForEach-Object {Get-WmiObject -Class Win32_OperatingSystem -ComputerName $_ -AsJob}&lt;/p&gt;
&lt;p&gt;With the snap of my fingers the job creation was off and running on over 1100 servers. It took maybe 30 seconds to create all the jobs. &amp;ldquo;Oh my&amp;hellip;,&amp;rdquo; I thought in disbelief, &amp;ldquo;Did that just happen that fast? No&lt;i&gt; &lt;/i&gt;way!&amp;rdquo; As it turns out, it most certainly did.&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/0083.wes_2D00_5_2D00_26_2D00_12_2D00_3.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/0083.wes_2D00_5_2D00_26_2D00_12_2D00_3.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;After the jobs finished scrolling by, I ran &lt;b&gt;Get-Job&lt;/b&gt; to check the status. To my surprise, other than a few &amp;ldquo;Running&amp;rdquo; and &amp;ldquo;Failed&amp;rdquo; jobs, all were &amp;ldquo;Completed&amp;rdquo;:&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/1526.wes_2D00_5_2D00_26_2D00_12_2D00_4.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/1526.wes_2D00_5_2D00_26_2D00_12_2D00_4.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Because all the jobs completed, I ran the following code to capture the data from the jobs and then exported the data to a CSV file:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $Jobs = Get-Job | Receive-Job | Select CSName, Caption&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $Jobs | Export-Csv -Path C:\Users\Brian\Desktop\2003Servers.csv -NoTypeInformation&lt;/p&gt;
&lt;p&gt;Later I went back to find out exactly how long it took to kick the jobs off, and it appears that it ran in &lt;b&gt;17.267&lt;/b&gt; seconds:&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/8270.wes_2D00_5_2D00_26_2D00_12_2D00_5.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8270.wes_2D00_5_2D00_26_2D00_12_2D00_5.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now keep in mind that after &amp;nbsp;the jobs finished scrolling by within Windows PowerShell, I ran &lt;b&gt;Get-Job&lt;/b&gt; and most had finished. So the total time taken to query that many servers was less than 25 to 30 seconds, that is AWESOME!&lt;/p&gt;
&lt;p&gt;With this information, I was able to complete the &amp;ldquo;True-Up&amp;rdquo; mission that my manager had given me in a timely manner. I was so happy with the sheer &amp;ldquo;Power&amp;rdquo; of Windows PowerShell that I reached out to my friend and shared the story. And now I have the privilege of sharing it with the community. I enjoy working daily in Windows PowerShell, and I hope you do too. Thanks for taking the time to listen to me ramble on about the &amp;ldquo;Shell.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;~Brian&lt;/p&gt;
&lt;p&gt;I don&amp;rsquo;t think you are rambling, Brian. In fact, I appreciate your enthusiasm. I can also tell you that the longer you work with Windows PowerShell, the greater that enthusiasm grows. I am constantly shouting out loud, &amp;ldquo;Dude, that is awesome!&amp;rdquo; So much so that the Scripting Wife simply ignores me&amp;mdash;at least I think that is why she ignores me sometimes. Anyway, Brian, thank you so very much for taking the time to share your experience with the Windows PowerShell scripting community. Join me tomorrow for more Windows PowerShell goodness.&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;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3499277" 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/Weekend+Scripter/">Weekend Scripter</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/Brian+Wilhite/">Brian Wilhite</category></item><item><title>Getting Directory Sizes in PowerShell</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/25/getting-directory-sizes-in-powershell.aspx</link><pubDate>Fri, 25 May 2012 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3499157</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3499157</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/25/getting-directory-sizes-in-powershell.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Guest blogger, Bill Stewart, discusses a Windows PowerShell function to determine folder size.&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. Guest blogger today is Bill Stewart. Bill Stewart is a scripting guru and a moderator for the Official Scripting Guys forum.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s Bill&amp;hellip;&lt;/p&gt;
&lt;p&gt;You have probably asked this question hundreds of times, &amp;ldquo;How big is that folder?&amp;rdquo; Of course, the typical GUI way to find out is to right-click the folder in Windows Explorer and open the folder&amp;rsquo;s properties. As with all things GUI, this does not scale well. For example, what if you need the size for 100 different folders?&lt;/p&gt;
&lt;p&gt;If you have worked with Windows PowerShell for any length of time, you know that it provides a pretty comprehensive set of tools. The trick is learning how to combine the tools to get the results you need. In this case, I know that Windows PowerShell can find files (&lt;b&gt;Get-ChildItem&lt;/b&gt;), and I know that it can count objects and sum a property on objects. A simple example would be a command like this:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-ChildItem | Measure-Object -Sum Length&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Get-ChildItem&lt;/b&gt; outputs a list of items in the current location (in files and folders, if your current location is in a file system), and &lt;b&gt;Measure-Object&lt;/b&gt; uses this list as input and adds together every input object&amp;rsquo;s &lt;b&gt;Length&lt;/b&gt; property (file size). In other words, this command tells you the count and sum of the sizes of all the files in the current directory.&lt;/p&gt;
&lt;p&gt;The &lt;b&gt;Measure-Object&lt;/b&gt; cmdlet outputs an object with five properties (including &lt;b&gt;Count&lt;/b&gt;, &lt;b&gt;Average&lt;/b&gt;, and &lt;b&gt;Sum&lt;/b&gt;). However, we only care about the &lt;b&gt;Count&lt;/b&gt; and &lt;b&gt;Sum&lt;/b&gt; properties, so let us refine our command a bit:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-ChildItem | Measure-Object -Sum Length | Select-Object Count, Sum&lt;/p&gt;
&lt;p&gt;Now we are using &lt;b&gt;Select-Object&lt;/b&gt; to select (hence the name) only the two properties we care about. The end result is a new output object that contains only those two properties.&lt;/p&gt;
&lt;p&gt;This is good as far as it goes, but I wanted my output object to include the directory&amp;rsquo;s name. In addition, while we are at it, let us use the names &amp;ldquo;Files&amp;rdquo; and &amp;ldquo;Size&amp;rdquo; instead of &amp;ldquo;Count&amp;rdquo; and &amp;ldquo;Sum.&amp;rdquo; To do this, I am going to output a custom object like this:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$directory = Get-Item .&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$directory | Get-ChildItem |&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; Measure-Object -Sum Length | Select-Object `&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @{Name="Path"; Expression={$directory.FullName}},&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @{Name="Files"; Expression={$_.Count}},&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @{Name="Size"; Expression={$_.Sum}}&lt;/p&gt;
&lt;p&gt;I need &lt;b&gt;$directory&lt;/b&gt; as a separate variable so I can include it in the output object. In addition, you can see here that I am using &lt;b&gt;Select-Object&lt;/b&gt; with a set of hash tables as a shorthand technique for creating a custom output object.&lt;/p&gt;
&lt;p&gt;In the following image (&lt;b&gt;Figure&amp;nbsp;1)&lt;/b&gt;, you can see the output from all three of the commands.&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/8463.hsg_2D00_5_2D00_25_2D00_12_2D00_1.jpg"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8463.hsg_2D00_5_2D00_25_2D00_12_2D00_1.jpg" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The output does not look that great, but remember that the presentation is less important than the content: We are outputting &lt;i&gt;objects&lt;/i&gt;, not text. Because the output is objects, we can sort, filter, and measure.&lt;/p&gt;
&lt;p&gt;To get the output we want (include the path name and change a couple of the property names), the commands can start to get a bit lengthy. So it makes sense to encapsulate the needed code in a script. Get-DirStats.ps1 is the script, and its syntax is as follows:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-DirStats [[-Path] &amp;lt;Object&amp;gt;] [-Only] [-Every] [-FormatNumbers] [-Total]&lt;/p&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-DirStats -LiteralPath &amp;lt;String[]&amp;gt; [-Only] [-Every] [-FormatNumbers] [-Total]&lt;/p&gt;
&lt;p&gt;As you can see, you can run the script by using two sets of mutually exclusive parameters. Windows PowerShell calls these &lt;i&gt;parameter sets&lt;/i&gt;. The parameter sets&amp;rsquo; names (&lt;i&gt;Path&lt;/i&gt; and &lt;i&gt;LiteralPath&lt;/i&gt;) are defined in the statement at the top of the script, and the script&amp;rsquo;s &lt;b&gt;CmdletBinding&lt;/b&gt; attribute specifies that &lt;i&gt;Path&lt;/i&gt; is the default parameter set.&lt;/p&gt;
&lt;p&gt;The &lt;i&gt;Path&lt;/i&gt; parameter supports pipeline input. Also, the &lt;i&gt;Path&lt;/i&gt; parameter is defined as being first on the script&amp;rsquo;s command line, so the &lt;i&gt;Path&lt;/i&gt; parameter name itself is optional. The &lt;i&gt;LiteralPath&lt;/i&gt; parameter is useful when a directory name contains characters that Windows PowerShell would normally interpret as wildcard characters (the usual culprits are the &lt;b&gt;[&lt;/b&gt; and the &lt;b&gt;]&lt;/b&gt; characters.) The &lt;i&gt;Path&lt;/i&gt; and &lt;i&gt;LiteralPath&lt;/i&gt; parameters are in different parameter sets, so they&amp;rsquo;re mutually exclusive.&lt;/p&gt;
&lt;p&gt;The &lt;i&gt;Only&lt;/i&gt; parameter calculates the directory size only for the named path(s), but not subdirectories (like what is shown in Figure&amp;nbsp;1). Normally, when we ask about the size of a directory, we&amp;rsquo;re asking about all of its subdirectories also. If you only care about counting and summing the sizes of the files in a single directory (but not its subdirectories), you can use the &lt;i&gt;Only&lt;/i&gt; parameter.&lt;/p&gt;
&lt;p&gt;The &lt;i&gt;Every&lt;/i&gt; parameter outputs an object for every subdirectory in the path. Without the &lt;i&gt;Every&lt;/i&gt; parameter, the script outputs an object for the first level of subdirectories only. The following image shows what I mean.&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/6232.hsg_2D00_5_2D00_25_2D00_12_2D00_2.jpg"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/6232.hsg_2D00_5_2D00_25_2D00_12_2D00_2.jpg" alt="Image of menu" title="Image of menu" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If we use the following command, the script will output an object for every directory in the left (navigation) pane (if we expand them all, as shown in the previous image).&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-DirStats -Path C:\Temp -Every&lt;/p&gt;
&lt;p&gt;If we omit the &lt;i&gt;Every&lt;/i&gt; parameter from this command, the script will only output the directories in the right pane. The script will still get the sizes of subdirectories if you omit the &lt;i&gt;Every&lt;/i&gt; parameter; the difference is in the number of output objects.&lt;/p&gt;
&lt;p&gt;The &lt;i&gt;FormatNumbers&lt;/i&gt; parameter causes the script to output numbers as formatted strings with thousands separators, and the &lt;i&gt;Total&lt;/i&gt; parameter outputs a final object after all other output that adds up the total number of files and directories for all output. These parameters are useful when running the script at a Windows PowerShell command prompt; but you shouldn&amp;rsquo;t use them if you&amp;rsquo;re going to do something else with the output (such as sorting or filtering) because the numbers will be text (with &lt;i&gt;FormatNumbers&lt;/i&gt;) and there will be an extra object (with &lt;i&gt;Total&lt;/i&gt;). The following image &amp;nbsp;shows an example command that uses the &lt;i&gt;&amp;nbsp;FormatNumbers&lt;/i&gt; and &lt;i&gt;Total&lt;/i&gt; parameters with US English thousands separators.&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/2318.hsg_2D00_5_2D00_25_2D00_12_2D00_3.jpg"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/2318.hsg_2D00_5_2D00_25_2D00_12_2D00_3.jpg" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Get-DirStats.ps1 supports pipeline input, so it uses the Begin, Process, and End script blocks. The script uses the following lines of code within the Begin script block to detect the current parameter set and whether input is coming from the pipeline:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$ParamSetName = $PSCmdlet.ParameterSetName&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;if ( $ParamSetName -eq "Path" ) {&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; $PipelineInput = ( -not $PSBoundParameters.ContainsKey("Path") ) -and ( -not $Path )&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;elseif ( $ParamSetName -eq "LiteralPath" ) {&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; $PipelineInput = $false&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;}&lt;/p&gt;
&lt;p&gt;The script uses the &lt;b&gt;$ParamSetName&lt;/b&gt; and &lt;b&gt;$PipelineInput&lt;/b&gt; variables later in the Process script block. The logic behind the definition of the &lt;b&gt;$PipelineInput&lt;/b&gt; variable is thus: &amp;ldquo;If the &lt;i&gt;Path&lt;/i&gt; parameter is not bound (that is, it was not specified on the script&amp;rsquo;s command line), and the &lt;b&gt;$Path&lt;/b&gt; variable is &lt;b&gt;$null&lt;/b&gt;, then the input is coming from the pipeline.&amp;rdquo; Both the &lt;b&gt;$ParamSetName&lt;/b&gt; and &lt;b&gt;$PipelineInput&lt;/b&gt; variables are used in the script&amp;rsquo;s Process script block.&lt;/p&gt;
&lt;p&gt;The beginning of script&amp;rsquo;s Process script block has the following code:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;if ( $PipelineInput ) {&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; $item = $_&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;else {&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; if ( $ParamSetName -eq "Path" ) {&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $item = $Path&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; elseif ( $ParamSetName -eq "LiteralPath" ) {&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $item = $LiteralPath&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;}&lt;/p&gt;
&lt;p&gt;The &lt;b&gt;$item&lt;/b&gt; variable will contain the path that the script will process. Thus, if the script&amp;rsquo;s input is coming from the pipeline, &lt;b&gt;$item&lt;/b&gt; will be the current pipeline object (&lt;b&gt;$_&lt;/b&gt;); otherwise, &lt;b&gt;$item&lt;/b&gt; will be &lt;b&gt;$Path&lt;/b&gt; or &lt;b&gt;$LiteralPath&lt;/b&gt; (depending on the current parameter set).&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Next, Get-DirStats.ps1 uses the &lt;b&gt;Get-Directory&lt;/b&gt; function as shown here:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;function Get-Directory {&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; param( $item )&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; if ( $ParamSetName -eq "Path" ) {&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( Test-Path -Path $item -PathType Container ) {&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $item = Get-Item -Path $item -Force&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; elseif ( $ParamSetName -eq "LiteralPath" ) {&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( Test-Path -LiteralPath $item -PathType Container ) {&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $item = Get-Item -LiteralPath $item -Force&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; if ( $item -and ($item -is [System.IO.DirectoryInfo]) ) {&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return $item&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;}&lt;/p&gt;
&lt;p&gt;The &lt;b&gt;Get-Directory&lt;/b&gt; function uses &lt;b&gt;Test-Path&lt;/b&gt; to determine if its parameter (&lt;b&gt;$item&lt;/b&gt;) is a container object and a file system directory (that is, a System.IO.DirectoryInfo object).&lt;/p&gt;
&lt;p&gt;If the &lt;b&gt;Get-Directory&lt;/b&gt; function returned &lt;b&gt;$null&lt;/b&gt;, the script writes an error to the error stream by using the &lt;b&gt;Write-Error&lt;/b&gt; cmdlet and exits the Process script block with the &lt;b&gt;return&lt;/b&gt; keyword.&lt;/p&gt;
&lt;p&gt;After validating that the directory exists in the file system, the script calls the &lt;b&gt;Get-DirectoryStats&lt;/b&gt; function, which is really the workhorse function in the script. The &lt;b&gt;Get-DirectoryStats&lt;/b&gt; function is basically a fancy version of the commands run in Figure 1. Here it is:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;function Get-DirectoryStats {&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; param( $directory, $recurse, $format )&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; Write-Progress -Activity "Get-DirStats.ps1" -Status "Reading '$($directory.FullName)'"&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; $files = $directory | Get-ChildItem -Force -Recurse:$recurse | Where-Object { -not $_.PSIsContainer }&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; if ( $files ) {&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Write-Progress -Activity "Get-DirStats.ps1" -Status "Calculating '$($directory.FullName)'"&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $output = $files | Measure-Object -Sum -Property Length | Select-Object `&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @{Name="Path"; Expression={$directory.FullName}},&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @{Name="Files"; Expression={$_.Count; $script:totalcount += $_.Count}},&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @{Name="Size"; Expression={$_.Sum; $script:totalbytes += $_.Sum}}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; else {&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $output = "" | Select-Object `&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @{Name="Path"; Expression={$directory.FullName}},&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @{Name="Files"; Expression={0}},&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @{Name="Size"; Expression={0}}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; if ( -not $format ) { $output } else { $output | Format-Output }&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;}&lt;/p&gt;
&lt;p&gt;This function uses the &lt;b&gt;Write-Progress&lt;/b&gt; cmdlet to inform the user running the script that something&amp;rsquo;s happening, and it uses a combination of the &lt;b&gt;Get-ChildItem&lt;/b&gt;, &lt;b&gt;Where-Object&lt;/b&gt;, &lt;b&gt;Measure-Object&lt;/b&gt;, and &lt;b&gt;Select-Object&lt;/b&gt; cmdlets to output a custom object. Note the use of the scoped variables (&lt;b&gt;$script:totalcount&lt;/b&gt; and &lt;b&gt;$script:totalbytes&lt;/b&gt;). These are used with the script&amp;rsquo;s &lt;i&gt;Total&lt;/i&gt; parameter, and they are output in the script&amp;rsquo;s &lt;b&gt;End&lt;/b&gt; script block.&lt;/p&gt;
&lt;p&gt;Drop this script into a directory in your path, and you can quickly find the sizes for directories in your file system. Remember that it outputs objects, so you can add tasks such as sort and filter, for example:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-DirStats -Path C:\Temp | Sort-Object -Property Size&lt;/p&gt;
&lt;p&gt;This command outputs the size of directories in C:\Temp, sorted by size.&lt;/p&gt;
&lt;p&gt;The entire script can be downloaded from the &lt;a href="http://gallery.technet.microsoft.com/scriptcenter/Outputs-directory-size-964d07ff" target="_blank"&gt;Script Repository&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;~Bill&lt;/p&gt;
&lt;p&gt;Thank you, Bill, for writing an interesting and useful blog. Join me tomorrow for more Windows PowerShell cool stuff.&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;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&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=3499157" 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/files/">files</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/storage/">storage</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/Bill+Stewart/">Bill Stewart</category></item><item><title>Use a Module to Simplify Your PowerShell Profile</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/24/use-a-module-to-simplify-your-powershell-profile.aspx</link><pubDate>Thu, 24 May 2012 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3499599</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>9</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3499599</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/24/use-a-module-to-simplify-your-powershell-profile.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Microsoft Scripting Guy, Ed Wilson, teaches how to use a Windows PowerShell module to simplify your profile.&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! I have a problem and I hope you can provide some answers. My Windows PowerShell profile is, I guess, a bit excessive. I have a function that customizes my Windows PowerShell command prompt. I created a number of custom aliases and a couple of Windows PowerShell drives. So far, so good. The problem is all the customized functions that I wrote and use on a regular basis. I have them all pasted into my profile as well. I am not saying I wrote all this stuff. Heck no! For example, the &lt;b&gt;Test-IsAdministrator&lt;/b&gt; and some of the other functions I use, I stole from you. The problem is that my profile is now more than 2,000 lines long. I have it grouped according to the way you said: aliases, variables, PS Drives, functions, and commands. But still it is a problem when I need to add stuff to it. I loved your blogs this week, because one problem I have is keeping things straight between the Windows PowerShell ISE and the Windows PowerShell console; but still, I need more help. Got any more good ideas?&lt;/p&gt;
&lt;p&gt;&amp;mdash;VG&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 VG,&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. Today, things are a bit groggy for me. I was up late last night listening to the Scripting Wife and Hal&amp;rsquo;s wife on the &lt;a href="http://powerscripting.wordpress.com/" target="_blank"&gt;PowerScripting Podcast&lt;/a&gt; last night. Things always go a bit long there with people hanging around in the chat room while Jon begins the lengthy process of editing the show. Although I do not exactly &lt;a href="http://en.wikipedia.org/wiki/Cinderella" target="_blank"&gt;turn into a pumpkin after midnight&lt;/a&gt;, my brain does begin to resemble a &lt;a href="http://en.wikipedia.org/wiki/List_of_gourds_and_squashes" target="_blank"&gt;gourd&lt;/a&gt;.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Note&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/b&gt;This is the fourth in a series of four blogs discussing the Windows PowerShell profile. The first blog, &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/21/understanding-the-six-powershell-profiles.aspx" target="_blank"&gt;Understanding the Six PowerShell Profiles&lt;/a&gt;, appeared on Monday. The second blog, &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/22/deciding-between-one-or-multiple-powershell-profiles.aspx" target="_blank"&gt;Deciding Between One or Multiple PowerShell Profiles&lt;/a&gt; debuted on Tuesday. The third blog in the series, &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/23/use-a-central-file-to-simplify-your-powershell-profile.aspx" target="_blank"&gt;Use a Central File to Simplify Your PowerShell Profile&lt;/a&gt;&lt;i&gt;, &lt;/i&gt;appeared yesterday. For additional information about the Windows PowerShell profile, refer to &lt;a href="http://blogs.technet.com/search/searchresults.aspx?q=profile&amp;amp;sections=7618" target="_blank"&gt;&amp;nbsp;this collection of blogs&lt;/a&gt; on the Hey, Scripting Guy! Blog. &amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Group similar functionality into a module&lt;/h1&gt;
&lt;p&gt;One of the main ways to clean up your Windows PowerShell profile is to group related items into modules. For example, suppose your Windows PowerShell profile contains a few utility functions such as the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A function &lt;a href="http://blogs.technet.com/search/searchresults.aspx?q=test-isadministrator&amp;amp;sections=7618" target="_blank"&gt;to determine admin rights&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;A function &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2010/05/15/hey-scripting-guy-weekend-scripter-how-can-i-use-wmi-to-detect-laptops.aspx" target="_blank"&gt;to determine if the computer is a laptop&lt;/a&gt; or desktop&lt;/li&gt;
&lt;li&gt;A function &lt;a href="http://blogs.technet.com/search/searchresults.aspx?q=test-isISEhost&amp;amp;sections=7618" target="_blank"&gt;to determine if the host is the Windows PowerShell ISE&lt;/a&gt; or Windows PowerShell console&lt;/li&gt;
&lt;li&gt;A function to determine if the &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/01/07/how-do-i-install-powershell-on-windows-7-and-other-questions.aspx#Q2" target="_blank"&gt;computer is 32-bit&lt;/a&gt; or 64-bit&lt;/li&gt;
&lt;li&gt;A function &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2010/07/18/hey-scripting-guy-weekend-scripter-how-can-i-create-display-and-then-delete-a-temporary-text-file.aspx" target="_blank"&gt;to write to a temporary file&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;All of these functions relate to the central theme of being utility types of functions. They are not specific to one technology, and they are in fact, helper functions that are useful in a wide variety of scripts and applications. It is also true that as useful as these utilities are, you might not need to use them everywhere, at all times. This is the advantage of moving the functionality into a module&amp;mdash;you can easily load and unload them as required.&lt;/p&gt;
&lt;h2&gt;Where to store the profile&lt;i&gt; &lt;/i&gt;module&lt;/h2&gt;
&lt;p&gt;There are two locations that are used by modules by default. The first is in the user module location in the users MyDocuments special folder. The following command points to the user module location on my computer.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Join-Path -Path $home -ChildPath documents\windowsPowerShell\Modules&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;&lt;b&gt;Note&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;The user module location does not exist by default. It must be created when you store the first module. For more information, refer to the Hey, Scripting Guy! blog, &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2010/01/20/hey-scripting-guy-january-20-2010.aspx" target="_blank"&gt;How Do I work with Windows PowerShell Module Paths&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The second location is in the System32 directory hierarchy. The following code uses the &lt;b&gt;Join-Path&lt;/b&gt; cmdlet and the &lt;b&gt;$pshome&lt;/b&gt; automatic variable to retrieve the system module folder on my system.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Join-Path -path $PSHOME -ChildPath modules&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;C:\Windows\System32\WindowsPowerShell\v1.0\modules&lt;/p&gt;
&lt;p&gt;If you run your system as a nonelevated user, do not use the user module location for modules that require elevation of privileges. This will be an exercise in futility because once you elevate the user account to include admin rights, your profile shifts to another location, and then you do not have access to the module you were attempting to access.&lt;/p&gt;
&lt;p&gt;Therefore, it makes sense to store modules that require admin rights in the System32 directory hierarchy. Store modules that do not require admin rights in the user profile module location. When modules reside in one of the two default locations, Windows PowerShell automatically picks up on them and displays them when you use the &lt;b&gt;ListAvailable&lt;/b&gt;&lt;i&gt; &lt;/i&gt;command as seen here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-Module &amp;ndash;ListAvailable&lt;/p&gt;
&lt;p&gt;However, this does not mean that you are limited to modules from only the default locations. If you are centralizing your Windows PowerShell profile and storing it on a shared network drive, it makes sense to likewise store the module (and the module manifest) in the shared network location.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Note&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Keep in mind that the Windows PowerShell profile is a script, as is a Windows PowerShell module. Therefore, your script execution policy impacts the ability to run scripts (and to load modules) from a shared network location. Even if you have a script execution policy of &lt;i&gt;unrestricted, &lt;/i&gt;if you have not added the network share to your trusted sites in Internet Explorer, you will be prompted each time you open Windows PowerShell. You can use Group Policy to set the Internet Explorer trusted sites for your domain, or you can add them manually. You may also want to examine &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2010/06/16/hey-scripting-guy-how-can-i-sign-windows-powershell-scripts-with-an-enterprise-windows-pki-part-1-of-2.aspx" target="_blank"&gt;code signing for your scripts&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;When you decide where to store your module (or modules), your Windows PowerShell profile mainly consists of a series of &lt;b&gt;Import-Module&lt;/b&gt; commands. For example, the following commands comprise my Windows PowerShell ISE profile. The first four commands import four modules. The last three commands, call functions from various modules to back up the profile, add menu items to the Windows PowerShell ISE, and create a Windows PowerShell drive for the locations of my modules.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;import-module PowerShellISEModule&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;import-module MenuModule&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;import-module SnippetModule&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;import-module copymodule&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;BackUp-Profile&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Add-MenuItems&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;New-ModuleDrives&lt;/p&gt;
&lt;p&gt;For more information about using a module to clean up your profile, refer to the Weekend Scripter blog, &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2010/11/06/weekend-scripter-clean-up-your-powershell-ise-profile-by-using-a-module.aspx" target="_blank"&gt;Clean Up Your PowerShell ISE Profile by Using a Module&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;VG, that is all there is to using a module to simplify your Windows PowerShell profile. This also concludes Profile Week on the Hey, Scripting Guy! Blog. Join me tomorrow for a great blog by Bill Stewart about working with directory sizes. Bill is a moderator for the Hey, Scripting Guys! Forum, and he is a really great resource for the Windows PowerShell community.&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;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3499599" 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/getting+started/">getting started</category></item><item><title>Use a Central File to Simplify Your PowerShell Profile</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/23/use-a-central-file-to-simplify-your-powershell-profile.aspx</link><pubDate>Wed, 23 May 2012 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3499358</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3499358</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/23/use-a-central-file-to-simplify-your-powershell-profile.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Microsoft Scripting Guy, Ed Wilson, shows how to use a central file to simplify configuring your Windows PowerShell profile.&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! So can you tell me without all the chatter, what is the best way to create a single Windows PowerShell profile? I don&amp;rsquo;t want to hear about a whole lot of other junk because I am rather busy. So please, as one American police person on television used to say, &amp;ldquo;Just the facts, just the facts.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&amp;mdash;ZQ&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 ZQ,&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. Today is the third day in a row that we have had the windows open and the air conditioner turned off. The cool breeze and sounds of birds playing in the lawn are a welcome relief to the incessant thrum of electric motors. I just fixed a pot of Gun Powder Green tea with a half spoonful of organic lavender and a cinnamon stick for my midmorning tea. I also opened the cookie jar, and retrieved the next to last Anzac biscuit. I gave the Scripting Wife the last Anzac biscuit in honor of her appearance tonight on the &lt;a href="http://powerscripting.wordpress.com/2012/05/21/up-next-staci-rottenberg-and-teresa-wilson-talk-about-life-as-a-powershell-wife/" target="_blank"&gt;PowerScripting Podcast&lt;/a&gt;. She and Hal&amp;rsquo;s wife will be the guests on the show tonight, and it is sure to be a hoot. We did pretty well at making the Anzac biscuits last as long as possible. We cannot find Anzac biscuits in Charlotte, so a friend who is a Windows PowerShell MVP in Australia shuttled them to us via another Windows PowerShell MVP from Charlotte. We retrieved the elusive biscuits in the parking lot of the Microsoft office in Charlotte one night following a Windows PowerShell User Group meeting.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Note&amp;nbsp;&amp;nbsp;&lt;/b&gt;&amp;nbsp;This is the third in a series of four blogs that discuss the Windows PowerShell profile. The first blog, &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/21/understanding-the-six-powershell-profiles.aspx" target="_blank"&gt;Understanding the Six PowerShell Profiles&lt;/a&gt;, appeared on Monday. The second blog, &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/22/deciding-between-one-or-multiple-powershell-profiles.aspx" target="_blank"&gt;Deciding Between One or Multiple PowerShell Profiles&lt;/a&gt; debuted on Tuesday. For additional information about the Windows PowerShell profile, refer to &lt;a href="http://blogs.technet.com/search/searchresults.aspx?q=profile&amp;amp;sections=7618" target="_blank"&gt;&amp;nbsp;this collection of blogs&lt;/a&gt; on the Hey, Scripting Guy! Blog.&lt;/p&gt;
&lt;h1&gt;One Windows PowerShell profile&amp;mdash;but which one?&lt;/h1&gt;
&lt;p&gt;One way to use a single Windows PowerShell profile is to put everything into the &lt;i&gt;all users, all hosts &lt;/i&gt;profile. I know some companies that create a standard Windows PowerShell profile for everyone in the company, and they use the &lt;i&gt;all users, all hosts &lt;/i&gt;profile as a means of standardizing their Windows PowerShell environment. The changes go in during the image build process; and therefore, the profile is available to machines built from that image.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Advantages of using the &lt;i&gt;all users, all hosts &lt;/i&gt;profile&lt;/b&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Simplicity. One location for everything, especially when added changes during the build process.&lt;/li&gt;
&lt;li&gt;One file affects all Windows PowerShell users and all Windows PowerShell hosts.&lt;/li&gt;
&lt;li&gt;No conflict between Admin users and non-admin users, both types of users use the same profile.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;$profile.AllUsersAllHosts&lt;/b&gt; always points to the correct file.&lt;/li&gt;
&lt;li&gt;Great for central management&amp;mdash;one file for all users of a machine.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;When to use the &lt;i&gt;all users, all hosts &lt;/i&gt;profile&lt;/b&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;For a personal profile when duties require elevation and non-elevation of permissions across multiple Windows PowerShell hosts.&lt;/li&gt;
&lt;li&gt;As part of a standard image build to deploy static functionality to numerous machines and users.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Disadvantages of using the &lt;i&gt;all users, all hosts &lt;/i&gt;profile&lt;/b&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You must have administrator rights on the current machine to make changes to the file.&lt;/li&gt;
&lt;li&gt;No distinction between different hosts&amp;mdash;some commands do not work in ISE, and others do not work in the Windows PowerShell console.&lt;/li&gt;
&lt;li&gt;No distinction between administrator users and non-admin users. Non-admin users cannot run some commands.&lt;/li&gt;
&lt;li&gt;The files are distributed among potentially thousands of different machines. To make one change to the profile, the file must copy to all machines that are using that profile. This can be a major issue for computers such as laptops that connect only occasionally to the network. It is also a problem when attempting to use a shutdown script on a Windows&amp;nbsp;8 device (because Windows&amp;nbsp;8 devices do not perform a true shutdown).&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;Use your own file&lt;/h1&gt;
&lt;p&gt;Because the Windows PowerShell profile is a Windows PowerShell script (with the added benefit of having a special name and residing in a special location), it means that anything that can be accomplished in a Windows PowerShell script can be accomplished in a Windows PowerShell profile. A much better approach to dealing with Windows PowerShell profiles is to keep the profile itself as simple as possible. But bring in the functionality you require via other means. One way to do this is to add the profile information you require to a file. Store that file in a central location, and then dot-source it to the profile.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Just the steps: Use a central profile script&lt;/b&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Create a Windows PowerShell script containing the profile information that you require. Include the aliases, variables, functions, Windows PowerShell drives, and commands to execute on start up of Windows PowerShell.&lt;/li&gt;
&lt;li&gt;In the Windows PowerShell profile script, dot-source the central profile file. The following command (placed in the &lt;b&gt;$profile&lt;/b&gt; script) brings in functionality that is stored in a Windows PowerShell script named myprofile.ps1 that resides in a shared folder named c:\fso:&lt;/li&gt;
&lt;/ol&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;strong&gt;. c:\fso\myprofile.ps1&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The advantages of using a central Windows PowerShell script to store your profile information is that only one location requires updating when you add additional functionally to your profile. In addition, if folder permissions permit, the central Windows PowerShell script becomes available to any user for any host on the local machine. If you store this central Windows PowerShell script on a network file share, you need to update only one file for the entire network.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Advantages of using a central script for a PowerShell profile&lt;/b&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;One place to modify for all users and all hosts having access to the file.&lt;/li&gt;
&lt;li&gt;Easy to keep functionality synchronized among all Windows PowerShell hosts and users.&lt;/li&gt;
&lt;li&gt;Makes it possible to have one profile for entire network.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;When to use a central script for a PowerShell profile&lt;/b&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Provide basic functionality among multiple hosts and multiple users.&lt;/li&gt;
&lt;li&gt;Use for single user who wants to duplicate capabilities between Windows PowerShell hosts.&lt;/li&gt;
&lt;li&gt;Use to provide a single profile for networked computers via a file share.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Disadvantages of using a central script for a PowerShell profile&lt;/b&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;More complicated due to multiple files.&lt;/li&gt;
&lt;li&gt;No access to the central file means no profile for the machine.&lt;/li&gt;
&lt;li&gt;It is possible that non-role specific commands become available to users.&lt;/li&gt;
&lt;li&gt;More complicated to filter out specific commands for specific hosts.&lt;/li&gt;
&lt;li&gt;One central script becomes very complicated to maintain when it grows to hundreds of lines.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;ZQ, that is all there is to using a central file for your Windows PowerShell profile. Windows PowerShell Profile Week will continue tomorrow when I will talk about using a Windows PowerShell module for a profile.&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;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&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=3499358" 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/getting+started/">getting started</category></item><item><title>Deciding Between One or Multiple PowerShell Profiles</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/22/deciding-between-one-or-multiple-powershell-profiles.aspx</link><pubDate>Tue, 22 May 2012 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3499142</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3499142</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/22/deciding-between-one-or-multiple-powershell-profiles.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Microsoft Scripting Guy, Ed Wilson, discusses some of the decision points between using one or multiple Windows PowerShell profiles.&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! OK, so I understand that there are different types of Windows PowerShell profiles (I liked your blog yesterday by the way). But you failed on one major point: How do I know which profile to use? For example, suppose it was different types of tea&amp;mdash;you have an Earl Grey, an English Breakfast, and a generic green tea. When would you drink which tea? I hope this makes my question clear. Thanks.&lt;/p&gt;
&lt;p&gt;&amp;mdash;BH&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 BH,&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. The Scripting Wife and I are getting ready for &lt;a href="http://www.cmschill.net/StringTheory/uncategorized/announcing-atlanta-techstravaganza-2012/" target="_blank"&gt;Atlanta TechStravaganza 2012&lt;/a&gt;. It happens on Friday June 1, 2012, and there are just a few tickets remaining. This event is going to be held at the Microsoft Office in Atlanta. It is free, and it features a number of awesome speakers (including me). There is, in fact, an entire Windows PowerShell track (as tracks for Windows Server and System Center). This high profile, high impact event will be awesome. So how did the Scripting Wife and I get ready for the Atlanta TechStravaganza? We were on the website of my favorite computer store making a shopping list because no trip to Atlanta is complete without a trip to my favorite computer store. My list is already running two pages long, so maybe I need to implement a dedup routine.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Note&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;This is the second in a series of four blogs that discuss the Windows PowerShell profile. The first blog, &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/21/understanding-the-six-powershell-profiles.aspx" target="_blank"&gt;Understanding the Six PowerShell Profiles&lt;/a&gt;&lt;i&gt;, &lt;/i&gt;appeared on Monday. For additional information about the Windows PowerShell profile, refer to &lt;a href="http://blogs.technet.com/search/searchresults.aspx?q=profile&amp;amp;sections=7618" target="_blank"&gt;this collection of blogs&lt;/a&gt; on the Hey, Scripting Guy! Blog.&lt;/p&gt;
&lt;h1&gt;Design considerations for profiles&lt;/h1&gt;
&lt;p&gt;The first thing to do when deciding how to implement your Windows PowerShell profile is to analyze the way in which you use Windows PowerShell. For example, if you confine yourself to running a few Windows PowerShell scripts from within the Windows PowerShell ISE, there is no reason to worry about a Windows PowerShell console profile. If you use a different Windows PowerShell scripting environment than the Windows PowerShell ISE, but you also work interactively from the Windows PowerShell console, you may need to add stuff to the other scripting environment&amp;rsquo;s profile (assuming it has one) in addition to the Windows PowerShell console profile. If you work extensively in the scripting environment and the Windows PowerShell console, and you find yourself desiring certain modifications to both environments, well&amp;hellip;that leads to a different scenario.&lt;/p&gt;
&lt;p&gt;There are three names used for the Windows PowerShell profiles. The names appear in the table that follows along with the profile usage.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;table border="1" cellspacing="0" cellpadding="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td width="319" valign="top"&gt;
&lt;p&gt;&lt;b&gt;Profile Name&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="319" valign="top"&gt;
&lt;p&gt;&lt;b&gt;Profile Usage&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="319" valign="top"&gt;
&lt;p&gt;Microsoft.PowerShell_profile.ps1&lt;/p&gt;
&lt;/td&gt;
&lt;td width="319" valign="top"&gt;
&lt;p&gt;Refers to profiles (current user or all users) for the Windows PowerShell console.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="319" valign="top"&gt;
&lt;p&gt;profile.ps1&lt;/p&gt;
&lt;/td&gt;
&lt;td width="319" valign="top"&gt;
&lt;p&gt;Refers to profiles (current user or all users) for all Windows PowerShell hosts.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="319" valign="top"&gt;
&lt;p&gt;Microsoft.PowerShellISE_profile.ps1&lt;/p&gt;
&lt;/td&gt;
&lt;td width="319" valign="top"&gt;
&lt;p&gt;Refers to profiles (current user or all users) for the Windows PowerShell ISE.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The distinction between the Windows PowerShell ISE profiles and the Windows PowerShell console profiles is the letters ISE in the name of the Windows PowerShell ISE profiles. The location of the Windows PowerShell profile determines the scoping (whether the profile applies to the current user or to all users). All user profiles (any one of the three profiles detailed in the previous table) appear in the Windows\system32\WindowsPowerShell\v1.0 directory; a location that is referenced by the &lt;b&gt;$pshome&lt;/b&gt; variable. The following script illustrates using the &lt;b&gt;$pshome&lt;/b&gt; variable to obtain this folder.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\Users\ed.IAMMRED&amp;gt; $PSHOME&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;C:\Windows\System32\WindowsPowerShell\v1.0&lt;/p&gt;
&lt;p&gt;The folder that contains the three current user Windows PowerShell profiles is the WindowsPowerShell folder in the user&amp;rsquo;s &lt;i&gt;mydocuments&lt;/i&gt; special folder. The location of the user&amp;rsquo;s &lt;i&gt;mydocuments &lt;/i&gt;special folder is obtained by using the &lt;b&gt;GetFolderPath&lt;/b&gt;&lt;i&gt; &lt;/i&gt;method from the System.Environment .NET Framework class. This technique is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; [environment]::getfolderpath("mydocuments")&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;C:\Users\ed.IAMMRED\Documents&lt;/p&gt;
&lt;p&gt;The table that follows details a variety of use-case scenarios, and it points to the profile to use for specific purposes.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;table border="1" cellspacing="0" cellpadding="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td width="415" valign="top"&gt;
&lt;p&gt;&lt;b&gt;Windows PowerShell Use&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="223" valign="top"&gt;
&lt;p&gt;&lt;b&gt;Location and Profile Name&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="415" valign="top"&gt;
&lt;p&gt;Near exclusive Windows PowerShell console work as a non-administrative user&lt;/p&gt;
&lt;/td&gt;
&lt;td width="223" valign="top"&gt;
&lt;p&gt;MyDocuments&lt;/p&gt;
&lt;p&gt;Microsoft.PowerShell_profile.ps1&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="415" valign="top"&gt;
&lt;p&gt;Near exclusive Windows PowerShell console work as an administrative user&lt;/p&gt;
&lt;/td&gt;
&lt;td width="223" valign="top"&gt;
&lt;p&gt;$PSHome&lt;/p&gt;
&lt;p&gt;Microsoft.PowerShell_profile.ps1&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="415" valign="top"&gt;
&lt;p&gt;Near exclusive Windows PowerShell ISE work as a non- administrative user&lt;/p&gt;
&lt;/td&gt;
&lt;td width="223" valign="top"&gt;
&lt;p&gt;MyDocuments&lt;/p&gt;
&lt;p&gt;Microsoft.PowerShellISE_profile.ps1&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="415" valign="top"&gt;
&lt;p&gt;Near exclusive Windows PowerShell ISE work as an administrative user&lt;/p&gt;
&lt;/td&gt;
&lt;td width="223" valign="top"&gt;
&lt;p&gt;$PSHome&lt;/p&gt;
&lt;p&gt;Microsoft.PowerShellISE_profile.ps1&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="415" valign="top"&gt;
&lt;p&gt;Balanced Windows PowerShell work as non- administrative user&lt;/p&gt;
&lt;/td&gt;
&lt;td width="223" valign="top"&gt;
&lt;p&gt;MyDocuments&lt;/p&gt;
&lt;p&gt;profile.ps1&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="415" valign="top"&gt;
&lt;p&gt;Balanced Windows PowerShell work as an administrative user&lt;/p&gt;
&lt;/td&gt;
&lt;td width="223" valign="top"&gt;
&lt;p&gt;$psHome&lt;/p&gt;
&lt;p&gt;profile.ps1&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Note&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/b&gt;Depending on how you perform administrative work, you may decide that you want to use a &lt;i&gt;current user &lt;/i&gt;type of profile. This would be because you log on with a specific account to perform administrative work. If your work requires that you log on with a number of different user accounts, it makes sense to use an &lt;i&gt;all users &lt;/i&gt;profile.&lt;/p&gt;
&lt;h2&gt;Using more than one profile&lt;/h2&gt;
&lt;p&gt;Many Windows PowerShell users end up using more than one Windows PowerShell profile. This may not be intentional, but that is how it winds up. What happens is that they begin by creating a &lt;i&gt;current user, current host &lt;/i&gt;profile via the Windows PowerShell &lt;b&gt;$profile&lt;/b&gt; variable. (For more information about this, refer to yesterday&amp;rsquo;s Hey, Scripting Guy! Blog, &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/21/understanding-the-six-powershell-profiles.aspx" target="_blank"&gt;Understanding the Six PowerShell Profiles&lt;/a&gt;.) After adding a number of great items in the Windows PowerShell profile, the user decides that it would nice to have the same features in the Windows PowerShell console&amp;mdash;or the Windows PowerShell ISE&amp;mdash;whichever was not the original source. Therefore, after creating an additional profile, the user soon realizes there is a duplication of work.&lt;/p&gt;
&lt;p&gt;Depending on how much you add to your Windows PowerShell profile, you may be perfectly fine with having multiple Windows PowerShell profiles. If your profile does not have very many items in it, using one Windows PowerShell profile for the Windows PowerShell console and another profile for the Windows PowerShell ISE may be a perfectly acceptable solution. Simplicity makes this approach work. For example, certain commands, such as the &lt;b&gt;Start-Transcript&lt;/b&gt; cmdlet, do not work in the Windows PowerShell ISE. In addition, certain commands, such as those requiring &lt;b&gt;STA&lt;/b&gt;, do not work by default in the Windows PowerShell console. By creating multiple &lt;b&gt;$profile&lt;/b&gt; profiles (&lt;i&gt;current user, current host), &lt;/i&gt;and only editing them from the appropriate environment, much complexity leaves the profile creation process.&lt;/p&gt;
&lt;p&gt;However, it will not become too long before duplication leads to inconsistency, and that leads to frustration, and finally to a desire for correction and solution. A better approach is to plan for multiple environments from the beginning.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Advantages of using more than one profile&lt;/b&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Simple&lt;/li&gt;
&lt;li&gt;&lt;b&gt;$profile&lt;/b&gt; always refers to the correct profile&lt;/li&gt;
&lt;li&gt;Removes concern about incompatible commands&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;When to use more than one profile&lt;/b&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;With a simple profile&lt;b&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;When you do not have administrator or non-elevated user requirements&lt;b&gt;&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Disadvantages of using more than one profile&lt;/b&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Duplication of effort&lt;/li&gt;
&lt;li&gt;Inconsistencies between profiles (for variables, functions, PSDrives, and aliases)&lt;/li&gt;
&lt;li&gt;Maintenance due to the number of potential profiles&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Using one profile&lt;/h2&gt;
&lt;p&gt;If you need to customize the Windows PowerShell console and the Windows PowerShell ISE (or other Windows PowerShell host), and you need to log on with multiple credentials, your need for Windows PowerShell profiles increases exponentially. Attempting to keep a number of different Windows PowerShell profiles in sync quickly becomes a maintenance nightmare. This is especially true if you are prone to making quick additions to your Windows PowerShell profile when you see a particular need.&lt;/p&gt;
&lt;p&gt;In addition to having a large number of different profiles, it is also possible for a Windows PowerShell profile to grow to inordinate proportions&amp;mdash;especially when you begin to add many nicely crafted Windows PowerShell functions and helper functions. One solution to the problem of profile bloat (in fact, the best solution) is to use modules. My Windows PowerShell ISE profile uses four modules. The profile itself consists of the lines that load the modules.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Note&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/b&gt;This approach of containing functionality for a profile inside modules, and then loading the modules from the profile file, is presented in the Hey, Scripting Guy! Blog, &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/10/21/create-a-really-cool-powershell-ise-profile.aspx" target="_blank"&gt;Create a Really Cool PowerShell ISE Profile&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Advantages of using one profile&lt;/b&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Less work&lt;/li&gt;
&lt;li&gt;Easier to keep different profiles in sync&lt;/li&gt;
&lt;li&gt;Consistency from different Windows PowerShell environments&lt;/li&gt;
&lt;li&gt;Portability (the profile can more easily travel to different machines)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;When to use one profile&lt;/b&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;With more complex profiles&lt;b&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;When your work requires multiple user accounts or multiple Windows PowerShell hosts&lt;b&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;If your work takes you to different computers or virtual machines&lt;b&gt;&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Disadvantages of using one profile&lt;/b&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;More complex to setup&lt;/li&gt;
&lt;li&gt;Requires more planning&lt;/li&gt;
&lt;li&gt;&lt;b&gt;$profile&lt;/b&gt; does not point to correct location&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;BH, that is all there is to deciding about how to work with Windows PowerShell profiles. Windows PowerShell Profile Week will continue tomorrow when I will talk about setting up a single profile environment.&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;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3499142" 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/getting+started/">getting started</category></item><item><title>Understanding the Six PowerShell Profiles</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/21/understanding-the-six-powershell-profiles.aspx</link><pubDate>Mon, 21 May 2012 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3498567</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3498567</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/21/understanding-the-six-powershell-profiles.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Microsoft Scripting Guy, Ed Wilson, discusses the six different Windows PowerShell profiles, and when to use each.&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! Dude, I have been reading some of the posts in your most excellent blog; and first of all, I want to say I think you are great. Now for the question: I do not get the Windows PowerShell profile. I mean I get it, but not really. Here is part of my problem. I put some things in the profile, and then I go back and they are not there. Like, what is up with that? I hope you can help me. By the way, I am, like, totally looking forward to seeing you and the Scripting Wife at TechEd 2012 in Orlando. You will know me, because I sort of look like &lt;a href="http://en.wikipedia.org/wiki/Steve_Urkel" target="_blank"&gt;Urkel&lt;/a&gt;, and I always wear plaid shirts (but I don&amp;rsquo;t wear suspenders).&lt;/p&gt;
&lt;p&gt;&amp;mdash;BB&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 BB,&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. Last week was an absolutely great week. The Scripting Wife and I had dinner one night with Rich from the NYC Windows PowerShell Users Group (he is also a moderator for the Scripting Guys forum and writer of a couple of guest blogs). Rich was kind enough to bring me some Gunpower green tea, and I am sipping some right now. It is wonderful with a half teaspoon of organic lavender added to the pot. We also had the PowerScripting Podcast with the two winners of the 2012 Scripting Games and Jeffrey Snover. That conversation was fun and informative. I also enjoy talking to Jeffrey, and I look forward to sitting-in on at least one of his sessions at Microsoft TechEd 2012.&lt;/p&gt;
&lt;h1&gt;Six, count &amp;lsquo;em, six different PowerShell profiles&lt;/h1&gt;
&lt;p&gt;BB, there is no doubt that you are a bit confused with Windows PowerShell profiles. There are, in fact, six different profiles. The Windows PowerShell console and the Windows PowerShell ISE have their own profiles. In addition, there are profiles for the current user and profiles for all users. The table that follows lists the six profiles and their associated locations.&lt;/p&gt;
&lt;table border="1" cellspacing="0" cellpadding="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td width="175" valign="top"&gt;
&lt;p&gt;&lt;b&gt;Description &lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="463" valign="top"&gt;
&lt;p&gt;&lt;b&gt;Path&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="175" valign="top"&gt;
&lt;p&gt;Current User, Current Host - console&lt;/p&gt;
&lt;/td&gt;
&lt;td width="463" valign="top"&gt;
&lt;p&gt;$Home\[My ]Documents\WindowsPowerShell\Profile.ps1&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="175" valign="top"&gt;
&lt;p&gt;Current User, All Hosts&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="463" valign="top"&gt;
&lt;p&gt;$Home\[My ]Documents\Profile.ps1&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="175" valign="top"&gt;
&lt;p&gt;All Users, Current Host - console&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="463" valign="top"&gt;
&lt;p&gt;$PsHome\Microsoft.PowerShell_profile.ps1&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="175" valign="top"&gt;
&lt;p&gt;All Users, All Hosts&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="463" valign="top"&gt;
&lt;p&gt;$PsHome\Profile.ps1&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="175" valign="top"&gt;
&lt;p&gt;Current user, Current Host - ISE&lt;/p&gt;
&lt;/td&gt;
&lt;td width="463" valign="top"&gt;
&lt;p&gt;$Home\[My ]Documents\WindowsPowerShell\Microsoft.P owerShellISE_profile.ps1&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="175" valign="top"&gt;
&lt;p&gt;&amp;nbsp;All users, Current Host - ISE&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="463" valign="top"&gt;
&lt;p&gt;$PsHome\Microsoft.PowerShellISE_profile.ps1&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Understanding the six Windows PowerShell profiles&lt;/h2&gt;
&lt;p&gt;The first thing to do to understand the six Windows PowerShell profiles is to keep in mind that they move. They change (sort of like the staircases at &lt;a href="http://en.wikipedia.org/wiki/Hogwarts" target="_blank"&gt;Hogwarts&lt;/a&gt;). As long as you realize that they are a moving target, you will be fine. In most cases, when talking about the Windows PowerShell profile, people are referring to the &lt;i&gt;current user, current&lt;/i&gt; &lt;i&gt;host&lt;/i&gt; profile. In fact, if no one qualifies the Windows PowerShell profile with its associated scope or description, it is safe to assume that they are talking about the &lt;i&gt;&lt;em&gt;C&lt;/em&gt;&lt;i&gt;urrent User, Current Host&lt;/i&gt;&amp;nbsp;&lt;/i&gt;profile.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Note&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/b&gt;A Windows PowerShell profile (any one of the six) is simply a Windows PowerShell script. It has a special name, and it resides in a special place, but it is simply a script. In this regard, it is sort of like the old-fashioned &lt;a href="http://en.wikipedia.org/wiki/AUTOEXEC.BAT" target="_blank"&gt;autoexec.bat&lt;/a&gt; batch file. Because the Windows PowerShell profile is a Windows PowerShell script, you must enable the Script Execution policy prior to configuring and using a Windows PowerShell profile. For information about the Script Execution policy refer to &lt;a href="http://blogs.technet.com/search/searchresults.aspx?q=%22Script%20execution%20policy%22&amp;amp;sections=7618" target="_blank"&gt;this collection of Hey, Scripting Guy! Blogs&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Examining the $profile variable&lt;/h2&gt;
&lt;p&gt;When you query the &lt;b&gt;$profile&lt;/b&gt; automatic variable, it returns the path to the &lt;em&gt;C&lt;/em&gt;&lt;i&gt;urrent User, Current Host&lt;/i&gt; profile. This makes sense, and it is a great way to easily access the path to the profile. The following script illustrates this technique from within the Windows PowerShell console.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; $profile&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;C:\Users\ed.IAMMRED\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1&lt;/p&gt;
&lt;p&gt;Inside the Windows PowerShell ISE, when I query the &lt;b&gt;$profile&lt;/b&gt; automatic variable, I receive the output that is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\Users\ed.IAMMRED&amp;gt; $profile&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;C:\Users\ed.IAMMRED\Documents\WindowsPowerShell\Microsoft.PowerShell&lt;b&gt;ISE&lt;/b&gt;_profile.ps1&lt;/p&gt;
&lt;p&gt;To save you a bit of analyzing&amp;hellip;&lt;/p&gt;
&lt;p&gt;The difference between the Windows PowerShell console &lt;i&gt;&lt;em&gt;C&lt;/em&gt;&lt;i&gt;urrent User, Current Host&lt;/i&gt;&amp;nbsp;&lt;/i&gt;profile path and the Windows PowerShell ISE &lt;em&gt;C&lt;/em&gt;&lt;i&gt;urrent User, Current Host&lt;/i&gt;&amp;nbsp;profile path is three letters: &lt;i&gt;ISE. &lt;/i&gt;&lt;/p&gt;
&lt;p&gt;BB, these three letters are probably causing you problems. More than likely, you are setting something in your Windows PowerShell console profile, and it is not available inside the Windows PowerShell ISE.&lt;/p&gt;
&lt;h3&gt;Unraveling the profiles&lt;/h3&gt;
&lt;p&gt;You can pipe the &lt;b&gt;$profile &lt;/b&gt;variable to the &lt;b&gt;Get-Member&lt;/b&gt; cmdlet and see additional properties that exist on the &lt;b&gt;$profile&lt;/b&gt; variable. This technique is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; $PROFILE | Get-Member -MemberType noteproperty | select name&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Name&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;----&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;AllUsersAllHosts&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;AllUsersCurrentHost&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;CurrentUserAllHosts&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;CurrentUserCurrentHost&lt;/p&gt;
&lt;p&gt;If you are accessing the &lt;b&gt;$profile&lt;/b&gt; variable from within the Windows PowerShell console, the &lt;b&gt;AllUsersCurrentHost&lt;/b&gt; and the &lt;b&gt;CurrentUserCurrentHost&lt;/b&gt; note properties refer to the Windows PowerShell console. If you access the &lt;b&gt;$profile&lt;/b&gt; variable from within the Windows PowerShell ISE, the &lt;b&gt;AllUsersCurrentHost&lt;/b&gt; and the &lt;b&gt;CurrentUserCurrentHost &lt;/b&gt;note properties refer to the Windows PowerShell ISE profiles.&lt;/p&gt;
&lt;h3&gt;Using the $profile variable to refer to more than the current host&lt;/h3&gt;
&lt;p&gt;When you reference the &lt;b&gt;$profile&lt;/b&gt; variable, by default it refers to the &lt;i&gt;&lt;em&gt;C&lt;/em&gt;&lt;i&gt;urrent User, Current Host&lt;/i&gt;&amp;nbsp;&lt;/i&gt;profile. If you pipe the variable to the &lt;b&gt;Format-List&lt;/b&gt; cmdlet, it still refers to the &lt;em&gt;C&lt;/em&gt;&lt;i&gt;urrent User, Current Host&lt;/i&gt;&amp;nbsp;profile. This technique is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; $PROFILE | Format-List *&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;C:\Users\ed.IAMMRED\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1&lt;/p&gt;
&lt;p&gt;This leads to a bit of confusion, especially because the &lt;b&gt;Get-Member&lt;/b&gt; cmdlet reveals the existence of multiple profiles and multiple note properties. The way to see all of the profiles for the current host, is to use the &lt;i&gt;force &lt;/i&gt;parameter. It reveals the hidden properties. The command illustrating this technique is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$PROFILE | Format-List * -Force&lt;/p&gt;
&lt;p&gt;The command and the associated output from the command are 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/4532.hsg_2D00_5_2D00_21_2D00_12_2D00_01.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/4532.hsg_2D00_5_2D00_21_2D00_12_2D00_01.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It is possible to directly access each of these specific properties just like you would access any other property&amp;mdash;via dotted notation. This technique is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$PROFILE.CurrentUserAllHosts&lt;/p&gt;
&lt;p&gt;The path to each of the four profiles for the Windows PowerShell console are 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/2308.hsg_2D00_5_2D00_21_2D00_12_2D00_02.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/2308.hsg_2D00_5_2D00_21_2D00_12_2D00_02.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Determine if a specific profile exists&lt;/h2&gt;
&lt;p&gt;To determine if a specific profile exists, use the &lt;b&gt;Test-Path &lt;/b&gt;cmdlet and the appropriate flavor&lt;i&gt; &lt;/i&gt;of the &lt;b&gt;$profile&lt;/b&gt; variable. For example, to determine if a &lt;i&gt;&lt;em&gt;C&lt;/em&gt;&lt;i&gt;urrent User, Current Host&lt;/i&gt;&amp;nbsp;&lt;/i&gt;profile exists you can use the &lt;b&gt;$profile&lt;/b&gt; variable with no modifier, or you can use the &lt;strong&gt;Cu&lt;/strong&gt;&lt;b&gt;rrentUserCurrentHost&lt;/b&gt; note property. The following example illustrates both of these.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; test-path $PROFILE&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;True&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; test-path $PROFILE.CurrentUserCurrentHost&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;True&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt;&lt;/p&gt;
&lt;p&gt;In the same manner, the other three profiles that apply to the current host (in this example, I am using the Windows PowerShell console) are determined to not exist. This is shown in the code that follows.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; test-path $PROFILE.AllUsersAllHosts&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;False&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; test-path $PROFILE.AllUsersCurrentHost&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;False&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; test-path $PROFILE.CurrentUserAllHosts&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;False&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt;&lt;/p&gt;
&lt;h2&gt;Creating a new profile&lt;/h2&gt;
&lt;p&gt;To create a new profile for &lt;i&gt;current user all hosts, &lt;/i&gt;use the &lt;strong&gt;Cu&lt;/strong&gt;&lt;b&gt;rrentUserAllHosts&lt;/b&gt;&lt;i&gt; &lt;/i&gt;property of the &lt;b&gt;$profile&lt;/b&gt; automatic variable, and the &lt;b&gt;New-Item&lt;/b&gt; cmdlet. This technique is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; new-item $PROFILE.CurrentUserAllHosts -ItemType file -Force&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Directory: C:\Users\ed.IAMMRED\Documents\WindowsPowerShell&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Mode&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LastWriteTime&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Length Name&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;&amp;nbsp;&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;-a---&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5/17/2012&amp;nbsp;&amp;nbsp; 2:59 PM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0 profile.ps1&lt;/p&gt;
&lt;p&gt;To open the profile for editing, use the&lt;b&gt; ise&lt;/b&gt;&lt;i&gt; &lt;/i&gt;alias as shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;ise $PROFILE.CurrentUserAllHosts&lt;/p&gt;
&lt;p&gt;When you are finished editing the profile, save it, close the Windows PowerShell console, reopen the Windows PowerShell console, and test that your changes work properly.&lt;/p&gt;
&lt;p&gt;BB, that is all there is to using the &lt;b&gt;$profile&lt;/b&gt; variable to discover different Windows PowerShell profiles. Windows PowerShell Profile Week will continue tomorrow when I will talk about editing and testing a Windows PowerShell profile.&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;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&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=3498567" 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/getting+started/">getting started</category></item><item><title>The Scripting Guys Reveal Their TechEd 2012 Schedule</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/20/weekend-scripter-scripting-guy-reveal-their-teched-2012-schedule.aspx</link><pubDate>Sun, 20 May 2012 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3498561</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3498561</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/20/weekend-scripter-scripting-guy-reveal-their-teched-2012-schedule.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: The Scripting Guys reveal their Microsoft TechEd 2012 schedule and all the Windows PowerShell goodness thereof.&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. Yesterday we played &lt;i&gt;WhatIf&lt;/i&gt; with the Scripting Wife about what sessions she would choose to attend at TechEd 2012 if she was not involved in meeting and greeting people at the Scripting Guys booth. Today, I am going to share my real schedule. Hope to see you at some of these sessions and events. Please don&amp;rsquo;t be shy come on by and say, &amp;ldquo;Hi.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Pre TechEd 2012:&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Friday night, June 8&lt;sup&gt;:&lt;/sup&gt; I will be at the speaker&amp;rsquo;s dinner for SQLSaturday #132 in Pensacola, FL.&lt;/p&gt;
&lt;p&gt;Saturday, June 9: I will be speaking at and attending other sessions at SQLSaturday #132 in Pensacola, FL.&lt;/p&gt;
&lt;h2&gt;At Microsoft TechEd 2012 in Orlando&lt;/h2&gt;
&lt;p&gt;Here is what I plan to be doing during TechEd 2012&amp;hellip;&lt;/p&gt;
&lt;h3&gt;Sunday, June 10&lt;/h3&gt;
&lt;p&gt;Morning&amp;nbsp;&lt;a href="http://northamerica.msteched.com/agenda#fbid=wcgxrpGa1ii" target="_blank"&gt;Registration&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;11:00 AM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Sign off on the Scripting Guys booth&lt;/p&gt;
&lt;p&gt;12:30 PM &amp;ndash; 5:00 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;a href="http://ineta.org/teched2012/" target="_blank"&gt;INETA Community Leadership Summit &lt;/a&gt;&lt;/p&gt;
&lt;p&gt;8:00 PM &amp;ndash; 11:00 PM&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;a href="http://thekreweblog.wordpress.com/2012/05/03/thekrewemng/" target="_blank"&gt;The Krewe Meet N Greet&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;Monday, June 11&lt;/h3&gt;
&lt;p&gt;7:00 AM - 8:30 AM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Breakfast&lt;/p&gt;
&lt;p&gt;9:00 AM - 10:30 AM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Keynote Session&lt;/p&gt;
&lt;p&gt;10:30 AM - 12:00 PM&lt;i&gt;&lt;/i&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Scripting Guys booth in the Connect zone&lt;/p&gt;
&lt;p&gt;12:00 PM &amp;ndash; 1:00 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Lunch&lt;/p&gt;
&lt;p&gt;3:00 PM - 4:15 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;a href="http://northamerica.msteched.com/topic/details/2012/WCL403" target="_blank"&gt;PowerShell Remoting in Depth | WCL403&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;4:45 PM - 6:00 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;a href="http://northamerica.msteched.com/topic/details/2012/WSV313" target="_blank"&gt;The Network Files, Case #53: Diagnosing Diseases of DNS | WSV313&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;6:00 PM &amp;ndash; 9:00 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Scripting Guys booth with the following guest schedule:&lt;/p&gt;
&lt;p&gt;6:00 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Special guest at the Scripting Guys booth will be Don Jones. Be sure to come by, say hello, and get an autograph.&lt;/p&gt;
&lt;p&gt;7:00 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Special guests, Rohn Edwards and Lido Paglia, winners from the 2012 Scripting Games.&lt;/p&gt;
&lt;p&gt;7:30 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;a href="http://blogs.technet.com/b/blainbar/" target="_blank"&gt;Blain Barton&lt;/a&gt; will be at the Scripting Guys booth to interview Rohn and Lido about their experiences in the 2012 Scripting Games for IT Time-TechNet Radio.&lt;/p&gt;
&lt;h3&gt;Tuesday, June 12&amp;nbsp;&lt;/h3&gt;
&lt;p&gt;10:00 AM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Blain Barton interviews me at the O&amp;rsquo;Reilly booth just prior to a book signing for IT Time-TechNet Radio.&lt;/p&gt;
&lt;p&gt;10:30 AM - 11:00 AM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Book signing at the O&amp;rsquo;Reilly booth&lt;/p&gt;
&lt;p&gt;11:30 AM - 12:30 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Lunch&lt;/p&gt;
&lt;p&gt;12:30 PM &amp;ndash; 5:00 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Scripting Guys booth&lt;/p&gt;
&lt;p&gt;6:15-9PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Scripting Guys area at Community Night in North Hall B&lt;/p&gt;
&lt;h3&gt;Wednesday, June 13&lt;/h3&gt;
&lt;p&gt;8:30 AM - 9:45 AM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;a href="http://northamerica.msteched.com/topic/details/2012/WSV415" target="_blank"&gt;Group Policy Reporting and Analysis with Windows PowerShell | WSV415 &lt;/a&gt;&lt;/p&gt;
&lt;p&gt;10:30 AM &amp;ndash; 3:00 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Scripting Guys booth&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;10:30 AM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Special guest at the Scripting Guys booth, Jeffery Hicks, so come by and meet &amp;lsquo;n greet with Jeffery.&lt;/p&gt;
&lt;p&gt;3:15 PM - 4:30 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;a href="http://northamerica.msteched.com/topic/details/2012/BOF11-ITP" target="_blank"&gt;Windows PowerShell Best Practices | BOF11-ITP &lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;I am cohosting this session with Don Jones.&lt;/p&gt;
&lt;p&gt;5:00 PM - 6:15 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;a href="http://northamerica.msteched.com/topic/details/2012/WSV414" target="_blank"&gt;Advanced Automation Using Windows PowerShell 3.0 | WSV414&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;Thursday, June 14&lt;/h3&gt;
&lt;p&gt;10:30 AM - 2:00 PM&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Scripting Guys booth&lt;/p&gt;
&lt;p&gt;7:30 PM - 12:00 AM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Closing Party&lt;/p&gt;
&lt;h3&gt;Friday, June 15&lt;/h3&gt;
&lt;p&gt;8:00 AM &amp;ndash; 12:00 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;a href="http://blogs.msdn.com/b/powershell/archive/2012/05/09/going-to-teched-join-us-to-build-a-solution-on-windows-powershell-3-0.aspx" target="_blank"&gt;Build a Solution on Windows PowerShell 3.0&lt;/a&gt; at the a Rosen Center&lt;/p&gt;
&lt;p&gt;And to conclude the week with more Windows PowerShell goodness&amp;hellip;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Off to Jacksonville, FL for the &lt;a href="http://itprocamp.com/jacksonville/" target="_blank"&gt;Jacksonville IT Pro Camp&lt;/a&gt; speaker&amp;rsquo;s dinner.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Saturday, June 16&lt;/b&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;8:00 AM &amp;ndash; 5:00 PM &amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;I will attend and speak at the &lt;a href="http://itprocamp.com/jacksonville/" target="_blank"&gt;Jacksonville IT Pro Camp&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Some special notes&amp;hellip;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;The Scripting Guys booth will have two people at all times, and about half the time, there will be three people there. Besides myself and Teresa (The Scripting Wife), &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/tags/daniel+cruz/" target="_blank"&gt;Daniel Cruz&lt;/a&gt; will be joining us to answer your questions and to interact with you. A big THANK YOU to Dan for volunteering to help out this year.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;I will update this page&lt;/strong&gt; with information about more special guests that will be showing up at the booth. So bookmark this page so you can keep track of the schedule during the week of TechEd 2012 in Orlando.&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;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&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=3498561" 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/Weekend+Scripter/">Weekend Scripter</category></item><item><title>Weekend Scripter: Scripting Wife Creates Her Ideal TechEd 2012 Schedule</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/19/weekend-scripter-scripting-wife-creates-her-ideal-teched-2012-schedule.aspx</link><pubDate>Sat, 19 May 2012 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3498532</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=3498532</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/19/weekend-scripter-scripting-wife-creates-her-ideal-teched-2012-schedule.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: The Scripting Wife plays &lt;i&gt;WhatIf&lt;/i&gt; and creates her ideal Microsoft TechEd 2012 schedule.&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. The Scripting Wife likes to use &lt;i&gt;WhatIf&lt;/i&gt; in her daily musings. She has also been hearing from a lot of people who are going to Microsoft TechEd for the first time. Last year was her first TechEd experience, and she hopes to improve her takeaways this year. When asked what her schedule would look like if she was not working at the Scripting Guys booth, she sat down with the catalog and came up with the following schedule. I will warn you that Teresa is very flexible, so although this would be her proposed schedule on paper, it by no means indicates what will or would actually occur.&lt;/p&gt;
&lt;p&gt;For example, she may have chosen a session to attend based on the content, but then she may meet a really interesting person after we arrive who is presenting at the same time as a session she had already written down as attending. The next thing I know, I may be getting an email from her on my Windows&amp;nbsp;7 smartphone that says, &amp;ldquo;My plans have changed and I am going to attend a different session than is on my schedule. I met this really cool person and I want to go to his session.&amp;rdquo; In truth, the chances are good that if you want to talk to the Scripting Wife, come by the Scripting Guys booth during nearly any hour that the Connect Zone is open, and she will probably be there. She loves talking to people who want to learn Windows PowerShell, but do not know where or how to begin.&lt;/p&gt;
&lt;p&gt;Now without further ado, here is the Scripting Wife&amp;rsquo;s schedule for &lt;a href="http://northamerica.msteched.com/?mtag=scriptingguys#fbid=nbM_Js3WK9x" target="_blank"&gt;Microsoft TechEd 2012&lt;/a&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/8765.TechEdImAttending.JPG"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/150x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8765.TechEdImAttending.JPG" alt="Image of TechEd logo" title="Image of TechEd logo" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Hello everyone! Scripting Wife is here. I need to say a couple of things so you can follow what I have written and chosen. By the way do you know how hard it is to choose between Don Jones and Mark Minasi? Both are dear friends and both are excellent speakers.&lt;/p&gt;
&lt;p&gt;First, I am going to list the three items that I will work on while I am not attending a session. There is one demo in The Learning Center (TLC) and there are two hands-on labs.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Demo&lt;/b&gt; &lt;b&gt;in S. Hall A:&lt;/b&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;a href="http://northamerica.msteched.com/topic/details/2012/WSV07-TLC" target="_blank"&gt;Windows Server 2012 Server Manager and PowerShell | WSV07-TLC &lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Whatever the size of your organization, you want to maximize IT operational cost efficiency. Windows Server 2012 offers excellent total cost of ownership as an integrated platform with comprehensive, multiserver manageability. It delivers capabilities to manage many servers and the devices connecting them&amp;mdash;whether they are physical or virtual, and whether they are on-premises or off. Specifically, Windows Server 2012 provides new multi-machine management capabilities, automation, improved compliance with industry management technology standards, and experiences which are unified across physical and virtual platforms. Visit the Windows Server 2012 Management booth to hear from experts about all the great new features.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Lab in S. Hall B: &lt;/b&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;a href="http://northamerica.msteched.com/topic/details/2012/WSV11-HOL" target="_blank"&gt;What's New in Windows PowerShell 3.0 | WSV11-HOL&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;This lab gets you up and running with the all-new Server Manager in Windows Server 2012. Topics covered include: deploying roles and features to a remote server, configuring a role on a remote server, monitoring remote servers, and troubleshooting a remote server. You will leave this lab with a solid grasp of how to use the new Server Manager to quickly and easily perform common server management tasks, local and remote.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Lab in S. Hall B: &lt;/b&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;a href="http://northamerica.msteched.com/topic/details/2012/WSV12-HOL" target="_blank"&gt;Introduction to Windows PowerShell Fundamentals | 3.0 WSV12-HOL &lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;This lab gets you up and running with Windows PowerShell, Microsoft's latest shell environment and scripting language. Topics covered include: file system navigation, help and discovery features, PowerShell scripts, working with WMI, working with the system registry, and working with Active Directory. You will leave this lab with a solid grasp of how to use PowerShell to quickly and easily perform common IT management tasks, and have a solid foundation to learn advanced PowerShell topics.&lt;/p&gt;
&lt;p&gt;And now for my session schedule...&lt;/p&gt;
&lt;h3&gt;Monday, June 11&lt;/h3&gt;
&lt;p&gt;9:00 AM - 10:30 AM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Keynote Session&lt;/p&gt;
&lt;p&gt;11:30 AM - 1:15 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Lunch&lt;/p&gt;
&lt;p&gt;1:15 PM - 2:30 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;a href="http://northamerica.msteched.com/topic/details/2012/DBI202" target="_blank"&gt;The 12 Reasons to Love Microsoft SQL Server 2012 | DBI202 &lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Speakers&lt;/b&gt;:&lt;b&gt; &lt;/b&gt;&lt;a href="http://northamerica.msteched.com/speaker/details/e5bdaf16-3332-e011-be0d-001ec953730b" target="_blank"&gt;Dandy Weyn&lt;/a&gt;, &lt;a href="http://northamerica.msteched.com/speaker/details/e4b4d37b-7732-e111-b325-001ec953730b" target="_blank"&gt;Thomas LaRock&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;In this demo-only session, discover 12 good reasons to love SQL Server 2012. Learn about AlwaysOn, ColumnStore Indexing, Data Quality Services, Transact-SQL Enhancements, Power View, SQL Server Data Tools, and so much more in a very demo-driven session. By the end of the session you will understand the key features and improvements in SQL Server 2012, and how they work together.&lt;/p&gt;
&lt;p&gt;3:00 PM - 4:15 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;a href="http://northamerica.msteched.com/topic/details/2012/WCL403" target="_blank"&gt;PowerShell Remoting in Depth | WCL403&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Speaker: &lt;/b&gt;&lt;a href="http://northamerica.msteched.com/speaker/details/a9f0bd55-6aec-df11-82f7-001ec953730b" target="_blank"&gt;Don Jones&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Remoting is a foundation feature in Windows PowerShell, and is poised to become one of the most&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; important protocols on your network, especially for remote client management and support. Do you know how it works? Can your troubleshoot it? Can you configure it in a variety of scenarios to meet your organization's needs for security and operations? Don Jones, PowerShell author and MVP, walks you through the nitty-gritty details of Remoting, showing examples for a variety of scenarios and covering its troubleshooting features in great detail.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;4:45 PM - 6:00 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;a href="http://northamerica.msteched.com/topic/details/2012/WSV321" target="_blank"&gt;Windows PowerShell Crash Course | WSV321&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Speakers: &lt;/b&gt;&lt;a href="http://northamerica.msteched.com/speaker/details/a9f0bd55-6aec-df11-82f7-001ec953730b" target="_blank"&gt;Don Jones&lt;/a&gt;, &lt;a href="http://northamerica.msteched.com/speaker/details/567a232e-2d3a-e011-86d4-001ec953730b" target="_blank"&gt;Jeffrey Snover&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Windows PowerShell 3.0 is here, and it is delivering on Microsoft's promise to make nearly everything in Windows manageable from the command-line. Are you finally going to learn the shell, or learn to say, "Would you like fries with that?" instead? Join PowerShell author, columnist, trainer, and MVP Don Jones (one of the world's most well-known PowerShell experts) in a crash course that shows you how to use the shell's key features. No scripting experience needed&amp;mdash;you'll use the shell as it is meant to be used to accomplish real administrative tasks with just a few commands. Also, learn how the shell can teach you how to use itself, setting you up for success with the new wave of Microsoft and third-party enterprise products.&lt;/p&gt;
&lt;p&gt;6:00 PM - 9:00 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;TechExpo Welcome Reception&lt;/p&gt;
&lt;h3&gt;Tuesday June 12&lt;/h3&gt;
&lt;p&gt;10:15 AM - 11:30 AM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;a href="http://northamerica.msteched.com/topic/details/2012/WSV306" target="_blank"&gt;Inside Windows Server 2012 Multi-Server Management Capabilities | WSV306&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Speakers: &lt;/b&gt;&lt;a href="http://northamerica.msteched.com/speaker/details/eeb288aa-1f5f-e011-8914-001ec953730b" target="_blank"&gt;Erin Chapple&lt;/a&gt;, &lt;a href="http://northamerica.msteched.com/speaker/details/567a232e-2d3a-e011-86d4-001ec953730b" target="_blank"&gt;Jeffrey Snover&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Windows Server 2012 will offer excellent total cost of ownership as an integrated platform with comprehensive, multicomputer manageability. Two areas in which Windows Server 2012 improves multicomputer management are Server Manager and Windows PowerShell 3.0. Server Manager in Windows Server 2012 helps you efficiently deploy and manage roles and features on the local server, on remote servers, and on both online and offline virtual hard disks. It also provides a multiserver experience where you can centralize your Windows Server management in a single view, and streamlined your server configuration and deployment from the same window. Windows PowerShell 3.0 provides an extensive platform to help you manage server roles and automate management tasks. With access to over 2300 cmdlets (a tenfold increase from the previous version), Windows PowerShell 3.0 offers comprehensive management across your datacenter. This session overviews these subjects in detail and prepares you for enhancing your management capability.&lt;/p&gt;
&lt;p&gt;11:30 AM - 1:30 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Lunch&lt;/p&gt;
&lt;p&gt;1:30 PM - 2:45 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;a href="http://northamerica.msteched.com/topic/details/2012/BOF05-ITP" target="_blank"&gt;Legal Structures of User Groups | BOF05-ITP&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Room S329&lt;/b&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Should your group incorporate or apply for non-profit status? What are the benefits and pitfalls of creating legal structures for IT Professional groups? Do you charge membership fees to the members to pay the legal obligations?&lt;/p&gt;
&lt;p&gt;3:15 PM - 4:30 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;a href="http://northamerica.msteched.com/topic/details/2012/WSV308" target="_blank"&gt;Standards Support and Interoperability in Windows Server 2012: Storage, Networking, and Management | &amp;nbsp;WSV308&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Speakers: &lt;/b&gt;&lt;a href="http://northamerica.msteched.com/speaker/details/1f3054aa-310a-e011-82f7-001ec953730b" target="_blank"&gt;Gene Chellis&lt;/a&gt;, &lt;a href="http://northamerica.msteched.com/speaker/details/567a232e-2d3a-e011-86d4-001ec953730b" target="_blank"&gt;Jeffrey Snover&lt;/a&gt;, &lt;a href="http://northamerica.msteched.com/speaker/details/a74ba4a9-c86a-e011-8914-001ec953730b" target="_blank"&gt;See-Mong Tan&lt;/a&gt;, &lt;a href="http://northamerica.msteched.com/speaker/details/27c0d288-2c28-e111-b325-001ec953730b" target="_blank"&gt;Wojtek Kozaczynski&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Windows has always implemented formal and industry standards but the Windows Server 2012 mission to be a Cloud OS required us to take this to a new level with investments in storage, networking and management standards. For example, in Windows Server 2012 the WSMAN standard is now the primary management protocol, with DCOM provided for backwards compatibility. Clearly this is not your father&amp;rsquo;s Windows Server. This 200-level session covers formal &amp;ldquo;de jure&amp;rdquo; standards including management (such as SMI-S, WSMAN and CIM), networking (such as IPv6, IPSec, DCB, DCTCP, NVGRE, ECMA Power standards and RDMA), and storage (such as NFS and iSCSI). We describe the technology, how Windows supports it, what benefits it brings, and what you need to change/do in order to get those benefits. We also discuss &amp;ldquo;de facto&amp;rdquo; standards such as VSS and SMB and describe how Microsoft enables and promotes interoperability using conferences, protocol documentation, plugfests and more to make Windows Server 2012 the most interoperable operating system on the planet. IT pros should come learn how Windows Server 2012 simplifies the tasks of architecting and running systems and how you should update your equipment purchasing guidelines. Developers and Partners should come to learn about new opportunities and preferred mechanisms to interoperate with Windows Server 2012.&lt;/p&gt;
&lt;p&gt;5:00 PM - 6:15 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;a href="http://northamerica.msteched.com/topic/details/2012/WSV311" target="_blank"&gt;Extending Applications to Everywhere! Your Guide to Securing RDS RemoteApps for the Internet | WSV311&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Speaker: &lt;/b&gt;&lt;a href="http://northamerica.msteched.com/speaker/details/0c6eb66e-b7ee-df11-82f7-001ec953730b" target="_blank"&gt;Greg Shields&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Your job as IT administrator is all about applications and data. You need to protect your users' data, and you need to ensure access to it via applications. But today's workforce requires us to make our applications available from everywhere. Creating your own Internet-based cloud infrastructure for corporate applications is quickly becoming a need for every environment, both large and small. You can create this today for very little cost using Microsoft Remote Desktop Services. RDS Guru and Microsoft MVP Greg Shields has been working with Terminal Services since its introduction in Windows NT 4.0 Terminal Services Edition, and in this deep dive session he presents the step-by-step approach to building a cloud-based remote applications infrastructure with enough industrial-grade security that even the most secure of networks will allow it. RDS has for too long been relegated to the sidelines. Attend this session and make secure, scalable, and inexpensive cloud applications a reality for your company.&lt;/p&gt;
&lt;p&gt;6:15 PM - 9:00 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Community Night. There will be a Scripting Guys area!&lt;/p&gt;
&lt;p&gt;9:00 PM - 1:00 AM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Jam Sessions&lt;/p&gt;
&lt;h3&gt;Wednesday June 13&lt;/h3&gt;
&lt;p&gt;8:30 AM - 9:45 AM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;a href="http://northamerica.msteched.com/topic/details/2012/WSV415" target="_blank"&gt;Group Policy Reporting and Analysis with Windows PowerShell | WSV415 &lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Speakers: &lt;/b&gt;&lt;a href="http://northamerica.msteched.com/speaker/details/e50f4d12-f3fb-df11-82f7-001ec953730b" target="_blank"&gt;Jeffery Hicks&lt;/a&gt;, &lt;a href="http://northamerica.msteched.com/speaker/details/52c5f3f6-edfb-df11-82f7-001ec953730b" target="_blank"&gt;Jeremy Moskowitz&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;In this session led by PowerShell MVP Jeffery Hicks and Group Policy MVP Jeremy Moskowitz, we discuss techniques for analyzing Group Policy objects to identify potential problems. We look at ways to identify Group Policy settings using PowerShell scripts and third-party tools.&lt;/p&gt;
&lt;p&gt;11:30 AM - 1:30 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Lunch&lt;/p&gt;
&lt;p&gt;1:30 PM - 2:45 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;a href="http://northamerica.msteched.com/topic/details/2012/WCL404" target="_blank"&gt;Turn PowerShell Commands into Reusable CLI and GUI Tools | WCL404&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Speakers: &lt;/b&gt;&lt;a href="http://northamerica.msteched.com/speaker/details/a9f0bd55-6aec-df11-82f7-001ec953730b" target="_blank"&gt;Don Jones&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Say you have written an incredible PowerShell command or script. How do you leverage that as a tool across your entire organization? Learn to turn those commands and scripts into tools that can be safely used by your less-technical colleagues, or even end users! PowerShell MVP and author Don Jones demonstrates a variety of approaches, including cmdlet-like command-line tools all the way up to fully-distributable GUI tools that you can build yourself!&lt;/p&gt;
&lt;p&gt;3:15 PM - 4:30 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;a href="http://northamerica.msteched.com/topic/details/2012/BOF11-ITP" target="_blank"&gt;Windows PowerShell Best Practices | BOF11-ITP&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Led by Windows PowerShell MVP, Don Jones, and Microsoft Scripting, Guy Ed Wilson&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;All of Microsoft's current operating systems and most of their server-based products have deep PowerShell integration, and that trend will continue. Same goes for the hardware and software vendors out there, large and small. You need to be on this train! You need to script! How do you know if you are doing it right? What does that even mean? Can you save time by using tried and tested techniques?&lt;/p&gt;
&lt;p&gt;5:00 PM - 6:15 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;a href="http://northamerica.msteched.com/topic/details/2012/WSV414" target="_blank"&gt;Advanced Automation Using Windows PowerShell 3.0 | WSV414&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Speakers: &lt;/b&gt;&lt;a href="http://northamerica.msteched.com/speaker/details/474007f2-2428-e111-b325-001ec953730b" target="_blank"&gt;Hemant Mahawar&lt;/a&gt;, &lt;a href="http://northamerica.msteched.com/speaker/details/48cb2a2e-1528-e111-b325-001ec953730b" target="_blank"&gt;Travis Jones&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;This session showcases the improvements to Windows PowerShell introduced in Windows Server 2012. Demos for this talk include how IT administrators can create cmdlet functionality without the need for programming skills, PowerShell Remoting, Jobs, Modules, Debugging, and Constrained Endpoints, among others.&lt;/p&gt;
&lt;h3&gt;Thursday, June 14&lt;/h3&gt;
&lt;p&gt;8:30 AM - 9:45 AM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;a href="http://northamerica.msteched.com/topic/details/2012/EXL203" target="_blank"&gt;How to Tell Your Manager You Need Quotas on Your Mailboxes | EXL203&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Speaker: &lt;/b&gt;&lt;a href="http://northamerica.msteched.com/speaker/details/4c6f8e9d-2d5a-e011-8914-001ec953730b" target="_blank"&gt;Bhargav Shukla&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;As systems offer bigger and bigger mailboxes and Microsoft has published whitepapers on large mailbox vision, it is important to understand the infrastructure to support such designs, what your company desires, and what the cost and operational impacts are. This session provides intelligent discussion about factors involved and cost benefits, to help you drive your infrastructure towards better manageability and stability.&lt;/p&gt;
&lt;p&gt;10:15 AM - 11:30 AM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;a href="http://northamerica.msteched.com/topic/details/2012/MGT302" target="_blank"&gt;Application Monitoring with Microsoft System Center Operations Manager 2012 | MGT302&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Speakers: &lt;/b&gt;&lt;a href="http://northamerica.msteched.com/speaker/details/ba170e05-9d82-e111-b8c3-001ec953730b" target="_blank"&gt;Aakash Mandhar&lt;/a&gt;, &lt;a href="http://northamerica.msteched.com/speaker/details/8d2972a6-547f-e111-94ad-001ec953730b" target="_blank"&gt;Daniele Muscetta&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;In this session we provide a summary of the application monitoring capabilities enabled through System Center 2012 Operations Manager against Microsoft .NET and Java applications, covering the platforms and supported configurations. See how System Center 2012 Operations Manager can provide critical availability, performance, and reliability information without requiring any custom instrumentation to the code or custom management packs.&lt;/p&gt;
&lt;p&gt;11:30 AM - 1:00 PM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Lunch&lt;/p&gt;
&lt;p&gt;7:30 PM - 12:00 AM&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Closing Party&lt;/p&gt;
&lt;p&gt;That is my &lt;i&gt;WhatIf&lt;/i&gt; schedule, and I think it has a nice balance to it. Hopefully, you will find it useful. Keep in mind, Microsoft TechEd 2012 is a huge event, and the Orlando Expo Center (according to the Scripting Guy) is like three miles long. So you should definitely bring comfortable walking shoes and also wear clothes that are comfortable. I look forward to seeing you if you get to come to TechEd 2012 in Orlando. There are still some slots available, so there is still time to register.&lt;/p&gt;
&lt;p&gt;~Scripting Wife&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;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&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=3498532" 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/Weekend+Scripter/">Weekend Scripter</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Scripting+Wife/">Scripting Wife</category></item><item><title>Use PowerShell to Find the History of USB Flash Drive Usage</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/18/use-powershell-to-find-the-history-of-usb-flash-drive-usage.aspx</link><pubDate>Fri, 18 May 2012 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3498124</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3498124</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/18/use-powershell-to-find-the-history-of-usb-flash-drive-usage.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Microsoft premier field engineer, Jason Walker, shows how to use Windows PowerShell to get a history of USB drive usage.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. I was talking to Jason Walker at the Charlotte Windows PowerShell User Group the other day. I asked him what cool things he was doing with Windows PowerShell, and he discussed a script he had recently written. I encouraged him to write a guest blog about the script. Today&amp;rsquo;s blog is a result of that conversation.&lt;/p&gt;
&lt;p&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/5381.HSG_2D00_5_2D00_18_2D00_12_2D00_1.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/150x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/5381.HSG_2D00_5_2D00_18_2D00_12_2D00_1.png" alt="Photo of Jason Walker" title="Photo of Jason Walker" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Jason Walker is a premier field engineer (PFE) at Microsoft, and he supports customers in the public arena. His primary job is supporting Exchange Server, but he jumps at the opportunity to flex his Windows PowerShell muscles to resolve any issue that may come up. It does not matter if it is related to Exchange Server. Jason also actively participates in the &lt;a href="http://powershellgroup.org/charlotte.nc" target="_blank"&gt;Charlotte PowerShell Users Group&lt;/a&gt;.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Twitter: &lt;a href="http://twitter.com/#!/AutomationJason" target="_blank"&gt;AutomationJason&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;USB ports are an awesome resource to any computer. They allow you quickly connect and use accessories such as mice, keyboards, and storage devices, just to name a few. However, USB storage devices are a popular vector bad guys use to get nefarious code onto a machine. With my customers being in the public sector, security is a top priority, and USB storage devices are not allowed. We could disable USB ports all together, but that would eliminate the ability to use other USB devices. Therefore, users are told to simply not use USB storage devices. The need came up to see if the users are playing by the rules and Windows PowerShell was the answer to that need.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;How do we find out if a USB storage device has been connect to a computer?&amp;rdquo; you ask. We look in the registry, of course. When a USB storage device is inserted into a machine, the USBSTOR key is created in the registry, and everything the operating system needs to know about that storage device is contained in that key. This is the complete path:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USBSTOR&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;/p&gt;
&lt;p&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/5353.hsg_2D00_5_2D00_18_2D00_12_2D00_2.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/350x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/5353.hsg_2D00_5_2D00_18_2D00_12_2D00_2.png" alt="Image of menu" title="Image of menu" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;When we expand the USBSTOR key, we see all the USB storage devices that have been used on the computer.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&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/2664.hsg_2D00_5_2D00_18_2D00_12_2D00_3.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/350x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/2664.hsg_2D00_5_2D00_18_2D00_12_2D00_3.png" alt="Image of menu" title="Image of menu" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;We see here that 15 different USB storage devices have been used on this machine. I know what you are thinking: &amp;ldquo;Whoever owns this machine is not very security conscience!&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;By looking at the subkey names, we can get an idea about what kind of storage device was used, but the data isn&amp;rsquo;t easily readable. When we dig deeper, we find a &lt;b&gt;FriendlyName&lt;/b&gt; property that is easily readable.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&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/7411.hsg_2D00_5_2D00_18_2D00_12_2D00_4.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/7411.hsg_2D00_5_2D00_18_2D00_12_2D00_4.png" alt="Image of menu" title="Image of menu" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Now we can see that a &amp;ldquo;SanDisk U3 Cruzer Micro USB Device&amp;rdquo; was used on this machine.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;To get this information, all we need Windows PowerShell to do is start from the USBSTOR key, recurse down two subkeys, and grab the &lt;b&gt;FriendlyName&lt;/b&gt; property. There are a couple ways we can get this data. We could do it in one line like this:&lt;/p&gt;
&lt;p&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/8463.hsg_2D00_5_2D00_18_2D00_12_2D00_5.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8463.hsg_2D00_5_2D00_18_2D00_12_2D00_5.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;But if we want to get this data from a remote machine, this will not work unless Windows PowerShell remoting is enabled&amp;mdash;and it most cases it is not. I believe the method that will work in the most number of scenarios is the Microsoft.Win32.RegistryKey class.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Note&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/b&gt;If you have Windows PowerShell remoting enabled, see last week&amp;rsquo;s Hey, Scripting Guy! blogs for a different approach to working with the registry. Saturday&amp;rsquo;s blog, &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/12/weekend-scripter-use-powershell-to-easily-modify-registry-property-values.aspx" target="_blank"&gt;Use PowerShell to Easily Modify Registry Property Values&lt;/a&gt;, contains links to the entire series.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I will explain the code that does all the heavy lifting.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;First, starting at USBSTOR, we get all the subkeys:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($Hive,$Computer)&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$USBSTORKey = $Reg.OpenSubKey($Key)&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$USBSTORSubKeys1 = $USBSTORKey.GetSubKeyNames()&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Then we go through each subkey ($USBSTORSubkeys1) and collect the child subkeys. We store them in $SubKeys2 as shown here:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;ForEach($SubKey1 in $USBSTORSubKeys1)&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&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;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; $Key2 = "SYSTEM\CurrentControlSet\Enum\USBSTOR\$SubKey1"&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; $RegSubKey2 = $Reg.OpenSubKey($Key2)&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; $SubkeyName2 = $RegSubKey2.GetSubKeyNames()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; $Subkeys2 &amp;nbsp;+= "$Key2\$SubKeyName2"&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; $RegSubKey2.Close()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; }#end foreach SubKey1&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Now we go through each Key in $Subkey2 and grab the &lt;b&gt;FriendlyName&lt;/b&gt; property of the key. The value of the property and the name of the computer are stored in a custom object so we can easily send our data to &lt;b&gt;Export-CSV&lt;/b&gt; or filter with &lt;b&gt;Where-Object&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;ForEach($Subkey2 in $Subkeys2)&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&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;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; $USBKey&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;= $Reg.OpenSubKey($Subkey2)&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; $USBDevice&amp;nbsp; = $USBKey.GetValue('FriendlyName')&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;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; $USBDevices += New-Object &amp;ndash;TypeName PSObject -Property @{&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&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;&amp;nbsp; USBDevice = $USBDevice&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&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;&amp;nbsp; Computer = $Computer&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&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;&amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&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;$USBKey.Close()&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;}#end foreach SubKey2&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;A few things to note are that the Remote Registry service must be running on the remote machine. I added a &lt;b&gt;Write-Progress&lt;/b&gt; cmdlet because when I first wrote this script it ran against hundreds of machines. The &lt;b&gt;Test-Connection&lt;/b&gt; cmdlet is not needed because the connection to the remote machine is inside the Try\Catch. However, during testing, it took 30+ seconds for the script to move to the next computer when trying to connect to a machine that was not online, so I added that as an option.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The script is written as a function, and it has comment-based Help with examples. Because it is written as a function, it will need to be dot-sourced. This is done by placing a dot and a space in front of the path to the script. When this is done, you can use the function just as you would a native Windows PowerShell cmdlet. Here is an example of how this is done:&lt;/p&gt;
&lt;p&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/6472.hsg_2D00_5_2D00_18_2D00_12_2D00_6.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/6472.hsg_2D00_5_2D00_18_2D00_12_2D00_6.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks, and I hope you can find this script useful when it&amp;rsquo;s time for you to flex your Windows PowerShell muscles.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;~Jason&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The complete script can be downloaded from the &lt;a href="http://gallery.technet.microsoft.com/scriptcenter/Get-USBHistory-707e43a3" target="_blank"&gt;Script Repository&lt;/a&gt;. Thank you for a great guest blog. I have often seen this registry key, but never thought about using it in the way you have here. Awesome job.&lt;/p&gt;
&lt;p&gt;&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;/p&gt;
&lt;p&gt;&lt;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&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=3498124" 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/registry/">registry</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/disk+drives+and+volumes/">disk drives and volumes</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/operating+system+/">operating system </category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/storage/">storage</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/Jason+Walker/">Jason Walker</category></item><item><title>Finding and Using Windows PowerShell Documentation</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/17/finding-and-using-windows-powershell-documentation.aspx</link><pubDate>Thu, 17 May 2012 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3498154</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3498154</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/17/finding-and-using-windows-powershell-documentation.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Microsoft Scripting Guy, Ed Wilson, talks about sources of Windows PowerShell documentation.&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! I like Windows PowerShell, but it does not seem to come with any documentation. What is up with this? It seems that Microsoft makes this great product, and then they did not produce any docs for how to use it. I just don&amp;rsquo;t get it.&lt;/p&gt;
&lt;p&gt;&amp;mdash;WB&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 WB,&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. The Scripting Wife and I are upstairs in my office. I am reading through the email sent to &lt;a href="mailto:scripter@microsoft.com"&gt;scripter@microsoft.com&lt;/a&gt;, and she is on her laptop hanging out on Twitter, Facebook, and whatever else she is up to these days. I am sipping a nice cup of Earl Gray tea with a bit of jasmine flower in it. I had some Earl Gray tea in Virginia Beach with jasmine in it, and it was really quite nice. So I looked around, and I found a place that sells organic, food-grade jasmine flowers, and I have been dying to try it out. It makes for a delightful afternoon tea.&lt;/p&gt;
&lt;h2&gt;Finding Windows PowerShell Help&lt;/h2&gt;
&lt;p&gt;WB, I must admit that my first expression was, &amp;ldquo;Dude, you have got to be kidding me.&amp;rdquo; But on reflection, I have received many emails asking about the &amp;ldquo;missing Windows PowerShell documentation.&amp;rdquo; If I think back about Windows NT&amp;nbsp;3.51, the product shipped with about a dozen floppy disks stuffed in a legal-sized envelope, about four pounds of books, and a heavy-duty cardboard box that was capable of protecting the most delicate crystal glasses during a transatlantic oceanic voyage.&lt;/p&gt;
&lt;p&gt;Although I liked the books that shipped with Windows NT&amp;nbsp;3.51 (I especially thought the troubleshooting book was excellent), I do know people that never opened those books. In addition, by the time Windows NT Server 3.51 received its fifth service pack, the books were terribly out-of-date. One thing we have done to help with the problem of out-of-date documentation is to enable books on demand. The Scripting Manager, Dave Bishop, wrote an excellent blog called &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/06/create-and-print-documentation-from-the-technet-library-or-msdn.aspx" target="_blank"&gt;How to Print Documents from the TechNet Library and MSDN&lt;/a&gt;&lt;i&gt;. &lt;/i&gt;&lt;/p&gt;
&lt;p&gt;So, the thing to keep in mind is that product documentation is changing. These days, we have many sources of information. In all of these different areas, Microsoft employees, Microsoft MVPs, and other community leaders take an active part in creating and in developing content. A quick review of some of the different sources is listed here.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="http://technet.microsoft.com/en-us/scriptcenter/dd742419.aspx" target="_blank"&gt;Video&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://social.technet.microsoft.com/wiki/contents/articles/4286.windows-powershell-en-us.aspx" target="_blank"&gt;Wiki&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://technet.microsoft.com/library/bb902776.aspx" target="_blank"&gt;Library pages&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.technet.com/b/heyscriptingguy/" target="_blank"&gt;Blogs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://social.technet.microsoft.com/Forums/en-US/ITCG/threads" target="_blank"&gt;Forums&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://technet.microsoft.com/en-us/scriptcenter/dd742419.aspx" target="_blank"&gt;Quizzes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://gallery.technet.microsoft.com/scriptcenter" target="_blank"&gt;Script Repositories&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://technet.microsoft.com/en-us/scriptcenter/dd742419.aspx" target="_blank"&gt;Books&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;On-the-box&lt;/li&gt;
&lt;li&gt;&lt;a href="http://bit.ly/scriptingguysfacebook" target="_blank"&gt;Facebook&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.microsoft.com/en-us/download/search.aspx?q=powershell" target="_blank"&gt;Windows PowerShell on the Microsoft Download Center&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.codeplex.com/site/search?query=powershell&amp;amp;ac=3" target="_blank"&gt;Windows PowerShell on CodePlex&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The image that follows illustrates &lt;a href="http://quizapp.cloudapp.net/default.aspx?quiz=powershell" target="_blank"&gt;the two Windows PowerShell quizzes&lt;/a&gt; that are available from the Learn PowerShell page on the TechNet Script Center. The quizzes correspond to two series of videos also available from the Learn PowerShell page. The quizzes be taken multiple times, and they represent a significant learning opportunity. Each question contains links to resources that explain the concept being tested.&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/6521.1A.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/6521.1A.png" alt="Image of menu" title="Image of menu" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Last year, the &lt;a href="http://www.microsoft.com/en-us/download/details.aspx?id=9706" target="_blank"&gt;Windows PowerShell language specification&lt;/a&gt; released. This several-hundred page document provides detailed documentation about how the Windows PowerShell language works. It is a great resource for anyone who wants to develop a deep understanding of how Windows PowerShell really works. Also last year, &lt;a href="http://www.microsoft.com/en-us/download/details.aspx?id=10552" target="_blank"&gt;an update to the on-the box core Windows PowerShell Help&lt;/a&gt; released in the Microsoft Download Center.&lt;/p&gt;
&lt;h2&gt;The online advantage&lt;/h2&gt;
&lt;p&gt;WB, one of the huge advantages to maintaining documentation online is that producing on-the-box documentation is a static process. A group of writers, editors, and tech reviewers develop the content, and it is printed and shipped. Most of the new online documentation represents an iterative process.&lt;/p&gt;
&lt;p&gt;For example, I write a Hey, Scripting Guy! Blog based on an email I receive. The blog is edited and published. Next, someone adds a comment that I missed something. I can immediately go back into the blog and edit it to reflect the new comment. Often this happens the same day. If you have a question about something in my book, you email the publisher. The publisher emails me. I make a revision, and forward it back to the publisher. The publisher forwards it to the printer, and in the next printing, the change takes place. This process takes months, not days. And it is a process that occurs for only the most grievous of errors.&lt;/p&gt;
&lt;h2&gt;Working locally &amp;ndash; searching globally&lt;/h2&gt;
&lt;p&gt;The Help that is returned from inside the Windows PowerShell console is basically out-of-date. It was out-of-date when the product shipped. This is because of the lag time between when the documentation must be completed and date when the final build of the product became ready to ship. Patches, updates, service packs, and other changes conspire to continue to make the Help out-of-date. Because of this situation (which is something we knew would happen), Windows PowerShell added the &lt;i&gt;online&lt;/i&gt; switch. This permits access to the latest Help updates at all times. The technique of using the &lt;i&gt;online &lt;/i&gt;switch is shown here where I obtain Help about the &lt;b&gt;Get-Process&lt;/b&gt; cmdlet from the online Microsoft TechNet Library.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-Help Get-Process &amp;ndash;Online&lt;/p&gt;
&lt;p&gt;When you execute the command, the Windows PowerShell console returns control to you. Internet Explorer opens to the appropriate page in the TechNet Library with the latest documentation for the command for which you inquired&amp;mdash;in this case the &lt;b&gt;Get-Process&lt;/b&gt; cmdlet.&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/4478.2A.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/4478.2A.png" alt="Image of menu" title="Image of menu" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;A way cool thing to do is to combine the online Help feature with the Build-a-Book feature that the Scripting Manager described in &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/06/create-and-print-documentation-from-the-technet-library-or-msdn.aspx" target="_blank"&gt;How to Print Documents from the TechNet Library and MSDN&lt;/a&gt;. This technique 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/8032._2300_A.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8032._2300_A.png" alt="Image of menu" title="Image of menu" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;WB, that is all there is to finding and using Windows PowerShell documentation. Join me tomorrow for a guest blog by Microsoft PFE, Jason Walker, as he talks about how to retrieve USB drive usage history. You DO NOT want to miss this most excellent blog&amp;mdash;just sayin&amp;rsquo;.&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;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&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=3498154" 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/getting+started/">getting started</category></item><item><title>Use the Get-Command PowerShell Cmdlet to Find Parameter Set Information</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/16/use-the-get-command-powershell-cmdlet-to-find-parameter-set-information.aspx</link><pubDate>Wed, 16 May 2012 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3498119</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3498119</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/16/use-the-get-command-powershell-cmdlet-to-find-parameter-set-information.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Microsoft Scripting Guy, Ed Wilson, shows how to use the Windows PowerShell Get-Command cmdlet to discover information about parameter sets.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Hey, Scripting Guy! Question" src="http://img.microsoft.com/library/media/1033/technet/images/scriptcenter/qanda/q-sm.jpg" /&gt;&amp;nbsp;Hey, Scripting Guy! One thing I don&amp;rsquo;t understand is parameter sets. I have heard about them, but I do not really find a good source of documentation about them. What is up with these things?&lt;/p&gt;
&lt;p&gt;&amp;mdash;BB&lt;/p&gt;
&lt;p&gt;&lt;img alt="Hey, Scripting Guy! Answer" src="http://img.microsoft.com/library/media/1033/technet/images/scriptcenter/qanda/a-sm.jpg" /&gt;&amp;nbsp;Hello BB,&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. Tonight is the night. At 9:30 PM Eastern Standard Time (-5 GMT) the &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/01/winners-of-the-2012-powershell-scripting-games-announced.aspx" target="_blank"&gt;two winners of the 2012 Scripting Games&lt;/a&gt; (Lido Paglia and Rohn Edwards), Jeffrey Snover, and myself appear with Jonathan Walz and Hal Rottenberg on the &lt;a href="http://powerscripting.wordpress.com/" target="_blank"&gt;PowerScripting Podcast&lt;/a&gt;. This event is recorded live, and there is a chat room set up so you can talk to your fellow listeners and&amp;nbsp;ask questions of the guests. Last year it was a lot of fun, and it should be a lot of fun this year too. Jeffrey Snover is always very interesting to listen to, and he is a great guy to talk to.&lt;/p&gt;
&lt;h2&gt;Understanding parameter sets&lt;/h2&gt;
&lt;p&gt;BB, parameter sets are different ways of using a Windows PowerShell command. For example, there are three ways to use the &lt;b&gt;Get-Process&lt;/b&gt; cmdlet. The one most everyone knows about is using &lt;b&gt;Get-Process&lt;/b&gt; to obtain information about a process by passing it a name. In fact, this is the default parameter set, and you do not need to do anything special to use this parameter set.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-Process notepad&lt;/p&gt;
&lt;p&gt;You can use the &lt;b&gt;Get-Command&lt;/b&gt; cmdlet to provide information about the default parameter set for a cmdlet. The following commands retrieve the default parameter set for the &lt;b&gt;Get-Process&lt;/b&gt; cmdlet.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; $a = gcm Get-Process&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; $a.DefaultParameterSet&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Name&lt;/p&gt;
&lt;p&gt;To view the other parameter sets, you can query the &lt;b&gt;ParameterSets&lt;/b&gt;&lt;i&gt; &lt;/i&gt;property. As illustrated here, the &lt;b&gt;Get-Process&lt;/b&gt; cmdlet has three different parameter sets.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; $a = gcm Get-Process&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; $a.ParameterSets | select name&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Name&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;----&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Name&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Id&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;InputObject&lt;/p&gt;
&lt;p&gt;Now BB, you may ask, &amp;ldquo;What is the big deal with a parameter set?&amp;rdquo; For one thing, it provides different ways of working with the same command. In addition, it prevents potential errors. Refer back to the &lt;b&gt;Get-Process&lt;/b&gt; cmdlet. An error would potentially arise if you specified that you wanted to see processes that had the name of calc.exe, but you specified a process ID that related to the notepad.exe process. Therefore, the &lt;i&gt;name &lt;/i&gt;parameter set permits the &lt;i&gt;name &lt;/i&gt;parameter, but excludes the &lt;i&gt;id &lt;/i&gt;parameter. This is why, at times, you might see the following error message:&lt;i&gt; Parameter set cannot be resolved&lt;/i&gt;&amp;hellip;&lt;/p&gt;
&lt;p&gt;As shown here, the message returns when you use parameters that when taken together, do not map to one specific parameter set.&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/2818.hsg_2D00_5_2D00_16_2D00_12_2D00_01.png"&gt;&lt;img title="Image of error message" alt="Image of error message" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/2818.hsg_2D00_5_2D00_16_2D00_12_2D00_01.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;One of the best ways to see the different parameter sets is to examine the output from the &lt;b&gt;Get-Help&lt;/b&gt; cmdlet. Each parameter details separately. 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/1057.hsg_2D00_5_2D00_16_2D00_12_2D00_02.png"&gt;&lt;img title="Image of command output" alt="Image of command output" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/1057.hsg_2D00_5_2D00_16_2D00_12_2D00_02.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Working with Get-Command&lt;/h2&gt;
&lt;p&gt;One of the problems with the &lt;b&gt;Get-Command&lt;/b&gt; cmdlet is that the command definition returns as &amp;ldquo;unstructured&amp;rdquo; text. But because you are working with Windows PowerShell, it is rather easy to correct this situation. The string data is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; $a = gcm get-process&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; $a.Definition&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-Process [[-Name] &amp;lt;String[]&amp;gt;] [-ComputerName &amp;lt;String[]&amp;gt;] [-Module] [-FileVersionI&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;nfo] [-Verbose] [-Debug] [-ErrorAction &amp;lt;ActionPreference&amp;gt;] [-WarningAction &amp;lt;ActionPr&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;eference&amp;gt;] [-ErrorVariable &amp;lt;String&amp;gt;] [-WarningVariable &amp;lt;String&amp;gt;] [-OutVariable &amp;lt;Stri&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;ng&amp;gt;] [-OutBuffer &amp;lt;Int32&amp;gt;]&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-Process -Id &amp;lt;Int32[]&amp;gt; [-ComputerName &amp;lt;String[]&amp;gt;] [-Module] [-FileVersionInfo] [-&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Verbose] [-Debug] [-ErrorAction &amp;lt;ActionPreference&amp;gt;] [-WarningAction &amp;lt;ActionPreferenc&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;e&amp;gt;] [-ErrorVariable &amp;lt;String&amp;gt;] [-WarningVariable &amp;lt;String&amp;gt;] [-OutVariable &amp;lt;String&amp;gt;] [-&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;OutBuffer &amp;lt;Int32&amp;gt;]&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-Process [-ComputerName &amp;lt;String[]&amp;gt;] [-Module] [-FileVersionInfo] -InputObject &amp;lt;Pr&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;ocess[]&amp;gt; [-Verbose] [-Debug] [-ErrorAction &amp;lt;ActionPreference&amp;gt;] [-WarningAction &amp;lt;Acti&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;onPreference&amp;gt;] [-ErrorVariable &amp;lt;String&amp;gt;] [-WarningVariable &amp;lt;String&amp;gt;] [-OutVariable &amp;lt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;String&amp;gt;] [-OutBuffer &amp;lt;Int32&amp;gt;]&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;When attempting to index into the parameter set, individual letters return. This problem appears here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; $a.Definition[0]&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;G&lt;/p&gt;
&lt;p&gt;But using the &lt;b&gt;Split&lt;/b&gt;&lt;i&gt; &lt;/i&gt;operator turns the output into an array. The &lt;b&gt;`r&lt;/b&gt; character is a special character that represents a carriage return. By splitting on these carriage returns, an array with three elements returns to the Windows PowerShell command prompt as shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; $a.Definition -split "`r"&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-Process [[-Name] &amp;lt;String[]&amp;gt;] [-ComputerName &amp;lt;String[]&amp;gt;] [-Module] [-FileVersionI&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;nfo] [-Verbose] [-Debug] [-ErrorAction &amp;lt;ActionPreference&amp;gt;] [-WarningAction &amp;lt;ActionPr&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;eference&amp;gt;] [-ErrorVariable &amp;lt;String&amp;gt;] [-WarningVariable &amp;lt;String&amp;gt;] [-OutVariable &amp;lt;Stri&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;ng&amp;gt;] [-OutBuffer &amp;lt;Int32&amp;gt;]&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-Process -Id &amp;lt;Int32[]&amp;gt; [-ComputerName &amp;lt;String[]&amp;gt;] [-Module] [-FileVersionInfo] [-&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Verbose] [-Debug] [-ErrorAction &amp;lt;ActionPreference&amp;gt;] [-WarningAction &amp;lt;ActionPreferenc&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;e&amp;gt;] [-ErrorVariable &amp;lt;String&amp;gt;] [-WarningVariable &amp;lt;String&amp;gt;] [-OutVariable &amp;lt;String&amp;gt;] [-&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;OutBuffer &amp;lt;Int32&amp;gt;]&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-Process [-ComputerName &amp;lt;String[]&amp;gt;] [-Module] [-FileVersionInfo] -InputObject &amp;lt;Pr&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;ocess[]&amp;gt; [-Verbose] [-Debug] [-ErrorAction &amp;lt;ActionPreference&amp;gt;] [-WarningAction &amp;lt;Acti&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;onPreference&amp;gt;] [-ErrorVariable &amp;lt;String&amp;gt;] [-WarningVariable &amp;lt;String&amp;gt;] [-OutVariable &amp;lt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;String&amp;gt;] [-OutBuffer &amp;lt;Int32&amp;gt;]&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Storing the output in a variable makes it easy to index into the array and retrieve a specific parameter set. This technique appears here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; $gps = $a.Definition -split "`r"&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; $gps[0]&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-Process [[-Name] &amp;lt;String[]&amp;gt;] [-ComputerName &amp;lt;String[]&amp;gt;] [-Module] [-FileVersionI&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;nfo] [-Verbose] [-Debug] [-ErrorAction &amp;lt;ActionPreference&amp;gt;] [-WarningAction &amp;lt;ActionPr&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;eference&amp;gt;] [-ErrorVariable &amp;lt;String&amp;gt;] [-WarningVariable &amp;lt;String&amp;gt;] [-OutVariable &amp;lt;Stri&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;ng&amp;gt;] [-OutBuffer &amp;lt;Int32&amp;gt;]&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; $gps[1]&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-Process -Id &amp;lt;Int32[]&amp;gt; [-ComputerName &amp;lt;String[]&amp;gt;] [-Module] [-FileVersionInfo] [-&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Verbose] [-Debug] [-ErrorAction &amp;lt;ActionPreference&amp;gt;] [-WarningAction &amp;lt;ActionPreferenc&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;e&amp;gt;] [-ErrorVariable &amp;lt;String&amp;gt;] [-WarningVariable &amp;lt;String&amp;gt;] [-OutVariable &amp;lt;String&amp;gt;] [-&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;OutBuffer &amp;lt;Int32&amp;gt;]&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; $gps[2]&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-Process [-ComputerName &amp;lt;String[]&amp;gt;] [-Module] [-FileVersionInfo] -InputObject &amp;lt;Pr&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;ocess[]&amp;gt; [-Verbose] [-Debug] [-ErrorAction &amp;lt;ActionPreference&amp;gt;] [-WarningAction &amp;lt;Acti&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;onPreference&amp;gt;] [-ErrorVariable &amp;lt;String&amp;gt;] [-WarningVariable &amp;lt;String&amp;gt;] [-OutVariable &amp;lt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;String&amp;gt;] [-OutBuffer &amp;lt;Int32&amp;gt;]&lt;/p&gt;
&lt;h2&gt;The ParameterSetInfo object&lt;/h2&gt;
&lt;p&gt;In addition to working with the definition of a Windows PowerShell cmdlet, the &lt;b&gt;ParameterSets&lt;/b&gt;&lt;i&gt; &lt;/i&gt;property contains an array of &lt;b&gt;CommandParameterSetInfo&lt;/b&gt; objects. The following command stores the object in a temporary variable, and then displays the members of the &lt;b&gt;CommandParameterSetInfo&lt;/b&gt; object.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; $a = get-command get-process&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; $a.ParameterSets | gm&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp; TypeName: System.Management.Automation.CommandParameterSetInfo&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MemberType Definition&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;----&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ---------- ----------&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Equals&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Method&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bool Equals(System.Object obj)&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;GetHashCode Method&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int GetHashCode()&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;GetType&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Method&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type GetType()&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;ToString&amp;nbsp;&amp;nbsp;&amp;nbsp; Method&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string ToString()&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;IsDefault&amp;nbsp;&amp;nbsp; Property&amp;nbsp;&amp;nbsp; System.Boolean IsDefault {get;}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Property&amp;nbsp;&amp;nbsp; System.String Name {get;}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Parameters&amp;nbsp; Property&amp;nbsp;&amp;nbsp; System.Collections.ObjectModel.ReadOnlyCollection`1[[Syste...&lt;/p&gt;
&lt;p&gt;Because the &lt;b&gt;ParameterSets&lt;/b&gt;&lt;i&gt; &lt;/i&gt;property returns a collection, it is possible to index directly into the collection and return information from it. However, indexing into the collection produces an output that seems a bit strange. This output 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/0131.hsg_2D00_5_2D00_16_2D00_12_2D00_03.png"&gt;&lt;img title="Image of command output" alt="Image of command output" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/0131.hsg_2D00_5_2D00_16_2D00_12_2D00_03.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;When you pipe a single instance of the &lt;b&gt;ParameterSets&lt;/b&gt;&lt;i&gt; &lt;/i&gt;to the &lt;b&gt;Get-Member&lt;/b&gt; cmdlet, everything still appears to be in the &lt;b&gt;Parameters&lt;/b&gt;&lt;i&gt; &lt;/i&gt;property. Therefore, it is time to use &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/06/18/top-ten-favorite-powershell-tricks-part-1.aspx" target="_blank"&gt;one of my favorite tricks&lt;/a&gt; (see favorite trick #3)&amp;mdash;the &lt;i&gt;ExpandProperty &lt;/i&gt;parameter &amp;nbsp;from the &lt;b&gt;Select-Object&lt;/b&gt; cmdlet. After I do this, everything falls into place. The two commands I use are shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$a = get-command get-process&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$a.ParameterSets[0] | select -ExpandProperty parameters&lt;/p&gt;
&lt;p&gt;The commands, and the associated output are 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/3302.hsg_2D00_5_2D00_16_2D00_12_2D00_04.png"&gt;&lt;img title="Image of command output" alt="Image of command output" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3302.hsg_2D00_5_2D00_16_2D00_12_2D00_04.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now it is trivial to see all of the parameters that are associated with a specific parameter set. In addition, the parameter aliases appear.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Note&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;For more information about parameter aliases, see &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/01/15/weekend-scripter-discovering-powershell-cmdlet-parameter-aliases.aspx" target="_blank"&gt;Weekend Scripter: Discovering PowerShell Cmdlet Parameter Aliases&lt;/a&gt;.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; $a = get-command get-process&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; $a.ParameterSets[0] | select -ExpandProperty parameters | ft name, ismandator&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;y, aliases&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IsMandatory Aliases&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;False {ProcessName}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;ComputerName&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; False {Cn}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Module&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; False {}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;FileVersionInfo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; False {FV, FVI}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Verbose&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;False {vb}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Debug&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; False {db}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;ErrorAction&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; False {ea}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;WarningAction&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; False {wa}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;ErrorVariable&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;False {ev}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;WarningVariable&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; False {wv}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;OutVariable&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; False {ov}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;OutBuffer&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; False {ob}&lt;/p&gt;
&lt;p&gt;BB, that is all there is to working with parameter sets. Join me tomorrow for more Windows PowerShell cool stuff.&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;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&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=3498119" 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/getting+started/">getting started</category></item><item><title>Find PowerShell Commands by Using the Get-Command Cmdlet</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/15/find-powershell-commands-by-using-the-get-command-cmdlet.aspx</link><pubDate>Tue, 15 May 2012 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3497946</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3497946</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/15/find-powershell-commands-by-using-the-get-command-cmdlet.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Microsoft Scripting Guy, Ed Wilson, shows how to use the &lt;b&gt;Get-Command&lt;/b&gt; cmdlet in Windows PowerShell to find various commands.&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! It all seems so easy for you. You want to find something by using Windows PowerShell and ba-da-bing, it is there. But for those of us who have not been using Windows PowerShell since before it was ever released, what is the secret? I mean using Windows PowerShell does not seem hard&amp;mdash;but there is so much of it. Every day, it seems that you perform this act, and it is like Windows PowerShell theatre. Of course, it works, but how did you find it in the first place? I hope I am making myself clear&amp;hellip;I do not even know where to start.&lt;/p&gt;
&lt;p&gt;&amp;mdash;RS&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 RS,&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. Today the day seems late, or early, depending on one&amp;rsquo;s perspective. It is nearly noon, and the sun does not appear to have awakened. The skies are all gray, and a thin drizzle of rainfall is providing a nice drink of cool water for our parched trees and plants. &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/tags/scripting+wife/" target="_blank"&gt;The Scripting Wife&lt;/a&gt; and I took our tea on the lanai this morning as we discussed &lt;a href="http://northamerica.msteched.com/?mtag=scriptingguys#fbid=gAcb1pKGvsw" target="_blank"&gt;Microsoft TechEd 2012 in Orlando&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;You need to get everything planned,&amp;rdquo; she said. &amp;ldquo;TechEd will be here sooner than you think.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Actually, I think TechEd will arrive exactly on Monday, June 11. We have to have the Scripting Guys booth set up by noon on June 10. That is also when we will see &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/06/11/what-i-learned-at-teched-2011-in-atlanta.aspx" target="_blank"&gt;Daniel Cruz&lt;/a&gt;, who is helping out in the booth. We may also get to see &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/01/winners-of-the-2012-powershell-scripting-games-announced.aspx" target="_blank"&gt;Rohn Edwards and Lido Paglia, the 2012 Scripting Games winners&lt;/a&gt;,&amp;rdquo; I said.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;It is going to be so much fun,&amp;rdquo; she replied, &amp;ldquo;And the TechEd party is going to be held at Universal Islands of Adventure theme park. How cool is that?&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;That is true, but I am really just looking forward to meeting people and to making new friends. For me, TechEd is all about the networking opportunities.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;So, speaking of networking,&amp;rdquo; she began, &amp;ldquo;How are you doing about creating the Scripting Guys guest schedule?&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Well, so far, I have Mark Minasi, Don Jones, Jeffery Hicks, Jeffrey Snover, and a few others scheduled to make guest appearances at the Scripting Guys booth. I also have a confirmation from O&amp;rsquo;Reilly press for my autograph session at their booth.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;So are you going to let me in on the secret? Or are you going to keep it all to yourself?&amp;rdquo; she asked.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Well, for now, I will keep it to myself,&amp;rdquo; I said with a smile.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Well, then for now, I am heading out with my friends,&amp;rdquo; she said with a smile, &amp;ldquo;I think we are going to check out that new store that opened up near the interstate.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;And with no further ado, she was gone.&lt;/p&gt;
&lt;p&gt;So, RS, I decided to head upstairs to check out the email sent to &lt;a href="mailto:scripter@microsoft.com"&gt;scripter@microsoft.com&lt;/a&gt;, and I ran across your email.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Note&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/b&gt;Tomorrow night, May 16, 2012 at 9:30 PM Eastern Standard Time (-5 GMT), the &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/01/winners-of-the-2012-powershell-scripting-games-announced.aspx" target="_blank"&gt;two winners of the 2012 Scripting Games&lt;/a&gt; (Lido Paglia and Rohn Edwards), Jeffrey Snover, and myself all appear with Jonathan Walz and Hal Rottenberg on the &lt;a href="http://powerscripting.wordpress.com/" target="_blank"&gt;PowerScripting Podcast&lt;/a&gt;. This event is recorded live, and there is a chat room set up so you can talk to your fellow listeners, in addition to asking questions of the guests. It will be a lot of fun, and you should not miss it if at all possible.&lt;/p&gt;
&lt;h2&gt;The easy way to find Windows PowerShell cmdlets&lt;/h2&gt;
&lt;p&gt;The first thing to keep in mind is that in Windows PowerShell, not everything is a cmdlet. There are language statements, functions, aliases, various objects (from the .NET Framework or COM), and even other executables&amp;mdash;all of which are utilizable from within Windows PowerShell. In Windows&amp;nbsp;8 Consumer Preview, this means you have around 1000 commands from which to choose. In Windows&amp;nbsp;7, the situation is not quite so overwhelming, but still you need to know how to find what you want.&lt;/p&gt;
&lt;p&gt;In Windows&amp;nbsp;7, much of the power of Windows PowerShell comes from WMI. (This is actually true in Windows 8 Consumer Preview also, but the WMI classes are exposed more directly.) For information about searching and working with WMI, see &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/tags/windows+powershell/wmi/" target="_blank"&gt;this collection of Hey, Scripting Guy! Blogs&lt;/a&gt;.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Note&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/b&gt; In yesterday&amp;rsquo;s blog, &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/14/discover-the-easy-way-to-begin-learning-windows-powershell.aspx" target="_blank"&gt;Discover the Easy Way to Begin Learning Windows PowerShell&lt;/a&gt;&lt;i&gt;, &lt;/i&gt;I talked about learning the Windows PowerShell Verb-Noun naming pattern as a way to develop an understanding of Windows PowerShell coverage. This technique will also aid in finding Windows PowerShell cmdlets.&lt;/p&gt;
&lt;p&gt;Two cmdlets are essential for discovering Windows PowerShell commands. The first is the &lt;b&gt;Get-Command&lt;/b&gt; cmdlet, and the second is the &lt;b&gt;Get-Help&lt;/b&gt; cmdlet. At first glance, the &lt;b&gt;Get-Command&lt;/b&gt; cmdlet might not appear to be all that useful. For example, you provide it with the name of a cmdlet, and basically what returns is the name of the cmdlet. This command is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-Command Get-Process&lt;/p&gt;
&lt;p&gt;The command and the output associated with the command illustrate the problem&lt;i&gt;. &lt;/i&gt;The default output does not appear to display much more information than you knew when you typed in the command. You figured it was a cmdlet, you knew the name of &lt;b&gt;Get-Process&lt;/b&gt;, and the definition does not add much additional information.&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/5153.hsg_2D00_5_2D00_15_2D00_12_2D00_01.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/5153.hsg_2D00_5_2D00_15_2D00_12_2D00_01.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;But, remember, everything in Windows PowerShell is an object. In fact, the &lt;b&gt;Get-Command&lt;/b&gt; cmdlet returns a &lt;b&gt;CmdletInfo&lt;/b&gt; object. This is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; Get-Command Get-Process | gm&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; TypeName: System.Management.Automation.CmdletInfo&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MemberType&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Definition&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;&amp;nbsp;&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;Equals&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Method&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bool Equals(System.Object obj)&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;GetHashCode&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Method&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int GetHashCode()&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;GetType&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Method&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type GetType()&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;ToString&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Method&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string ToString()&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;CommandType&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Property&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Management.Automation.CommandTypes Comm...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;DefaultParameterSet Property&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.String DefaultParameterSet {get;}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Definition&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Property&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.String Definition {get;}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;HelpFile&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Property&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.String HelpFile {get;}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;ImplementingType&amp;nbsp;&amp;nbsp;&amp;nbsp; Property&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Type ImplementingType {get;}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Module&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Property&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Management.Automation.PSModuleInfo Modu...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;ModuleName&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Property&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.String ModuleName {get;}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Property&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.String Name {get;}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Noun&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Property&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.String Noun {get;}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;OutputType&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Property&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Collections.ObjectModel.ReadOnlyCollect...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Parameters&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Property&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Collections.Generic.Dictionary`2[[Syste...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;ParameterSets&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Property&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Collections.ObjectModel.ReadOnlyCollect...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PSSnapIn&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Property&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Management.Automation.PSSnapInInfo PSSn...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Verb&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Property&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.String Verb {get;}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Visibility&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Property&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Management.Automation.SessionStateEntry...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;DLL&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ScriptProperty System.Object DLL {get=$this.ImplementingType....&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;HelpUri&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ScriptProperty System.Object HelpUri {get=try...&lt;/p&gt;
&lt;p&gt;Based on the members of the &lt;b&gt;CmdletInfo&lt;/b&gt; object, there appears to be a lot of information available about the cmdlet. The easiest way to view this information is to pipe the output from the &lt;b&gt;Get-Command&lt;/b&gt; cmdlet to the &lt;b&gt;Format-List&lt;/b&gt; cmdlet and to use a wild card character to choose all available properties. The command is shown here (&lt;b&gt;fl&lt;/b&gt; is an alias for the &lt;b&gt;Format-List&lt;/b&gt; cmdlet).&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-Command Get-Process | fl *&lt;/p&gt;
&lt;p&gt;The command, and the output associated with the command are 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/5670.hsg_2D00_5_2D00_15_2D00_12_2D00_02.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/5670.hsg_2D00_5_2D00_15_2D00_12_2D00_02.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In yesterday&amp;rsquo;s Hey, Scripting Guy! Blog, I talked about working with Windows PowerShell verbs&lt;i&gt; &lt;/i&gt;as a way of understanding available commands. When you know and understand the various verbs, using the &lt;b&gt;Get-Command&lt;/b&gt; cmdlet becomes much more valuable. For example, when you are looking for information about various items, you know you will more than likely use the &lt;b&gt;get&lt;/b&gt;&lt;i&gt; &lt;/i&gt;verb. Therefore, use the &lt;b&gt;Get-Command&lt;/b&gt; cmdlet to retrieve only cmdlets that use the &lt;b&gt;get&lt;/b&gt;&lt;i&gt; &lt;/i&gt;verb. This command is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-Command &amp;ndash;verb get&lt;/p&gt;
&lt;p&gt;If you seek cmdlets that will assign a new value to something, you more than likely are looking for a cmdlet that uses the &lt;b&gt;set&lt;/b&gt;&lt;i&gt; &lt;/i&gt;verb. The following command retrieves these types of cmdlets.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-Command &amp;ndash;verb set&lt;/p&gt;
&lt;h2&gt;Use nouns&lt;i&gt; &lt;/i&gt;for cmdlets&lt;/h2&gt;
&lt;p&gt;One of the things that tends to confuse beginners is the difference between the &lt;i&gt;name &lt;/i&gt;and the &lt;i&gt;noun &lt;/i&gt;parameters. The &lt;b&gt;Get-Command&lt;/b&gt; cmdlet has multiple parameter sets, and when you use the &lt;i&gt;verb &lt;/i&gt;or the &lt;i&gt;noun &lt;/i&gt;parameter, the &lt;b&gt;Get-Command&lt;/b&gt; cmdlet only returns cmdlets. If you use the &lt;i&gt;name &lt;/i&gt;parameter, &lt;b&gt;Get-Command&lt;/b&gt; finds cmdlets, executables, functions, aliases, and other types of commands.&lt;/p&gt;
&lt;p&gt;A good way to find commands is to use wild cards. For example, the following command returns any command containing the letters &lt;i&gt;adapter &lt;/i&gt;within the name of the command. The output reveals that one command meets this filter.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; gcm -Name *adapter*&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;CommandType&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Definition&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;Application&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AdapterTroubleshooter.exe&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C:\Windows\system32\AdapterTro...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Note&amp;nbsp;&amp;nbsp;&lt;/b&gt;&amp;nbsp;Because the &lt;b&gt;Get-Command&lt;/b&gt; cmdlet returns more than Windows PowerShell cmdlets, I often use it to help me locate various Windows executables. Because the Windows PowerShell console is generally open on my computer, it is faster for me to use than to use Windows Search.&lt;/p&gt;
&lt;p&gt;In the following image, I first look for commands related to &lt;i&gt;process. &lt;/i&gt;The first results (obtained by using the &lt;i&gt;name &lt;/i&gt;parameter) contain a number of applications, in addition to several Windows PowerShell cmdlets. When I limit the results to only cmdlets that have a &lt;i&gt;noun &lt;/i&gt;related to &lt;i&gt;process &lt;/i&gt;the results are more directed.&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/7875.hsg_2D00_5_2D00_15_2D00_12_2D00_03.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/7875.hsg_2D00_5_2D00_15_2D00_12_2D00_03.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;RS, that is all there is to using the &lt;b&gt;Get-Command&lt;/b&gt; cmdlet to search for cmdlets. Join me tomorrow when I will talk about additional ways to use &lt;b&gt;Get-Command&lt;/b&gt;. It will be a very cool blog (and one not only for beginners).&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;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3497946" 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/getting+started/">getting started</category></item><item><title>Discover the Easy Way to Begin Learning Windows PowerShell</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/14/discover-the-easy-way-to-begin-learning-windows-powershell.aspx</link><pubDate>Mon, 14 May 2012 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3497569</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3497569</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/14/discover-the-easy-way-to-begin-learning-windows-powershell.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Microsoft Scripting Guy, Ed Wilson, looks at Windows PowerShell naming conventions to simplify learning Windows PowerShell.&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! I have a feeling that I am quickly falling behind the Windows PowerShell wave. I am an Exchange Server admin where I work, and we are planning our deployment of Exchange Server&amp;nbsp;2010. I was searching for information when I ran across some of your &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/tags/windows+powershell/microsoft+exchange+2010/" target="_blank"&gt;blogs about using Windows PowerShell with Exchange Server 2010&lt;/a&gt;. I quickly realized that I do not know very much about Windows PowerShell. Here is the problem, it seems like everyone else in the world knows way more about Windows PowerShell than I do. I know that when Windows Server &amp;ldquo;8&amp;rdquo; Beta ships, there will be even another version of Windows PowerShell. So should I wait until Windows Server &amp;ldquo;8&amp;rdquo; Beta and then learn the new Windows PowerShell, or should I begin learning the current version of Windows PowerShell?&lt;/p&gt;
&lt;p&gt;&amp;mdash;GB&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 GB,&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. The other night, the Scripting Wife and I had dinner with Brian who is a member of the Charlotte Windows PowerShell User Group. In addition to answering lots of questions about Windows PowerShell and providing a decent amount of career guidance, the conversation also lingered for a while about tea. I thought about writing a blog called &lt;i&gt;The Fundamentals of Tea&lt;/i&gt;&amp;mdash;and I might do so on my personal blog. The problem is how does one describe the taste of Earl Gray tea to someone who has never tasted it before? Perhaps the best thing is to teach someone how to properly brew a nice cup of tea, and then allow them to taste some of my favorite teas. After all, there are literally hundreds of teas in the world, but they generally fall into just a few tea families. As you experience the flavors, you can find the types of tea that interest you.&lt;/p&gt;
&lt;p&gt;GB, the situation with learning Windows PowerShell is similar to learning about the world of tea. There are a few basic things you need to learn. A little grouping can be done to aid with the different types of Windows PowerShell cmdlets, and then from there, the process is one of exploring where your interests lie.&lt;/p&gt;
&lt;h2&gt;Windows PowerShell cmdlet naming helps you learn&lt;/h2&gt;
&lt;p&gt;One of the great things about Windows PowerShell is the verb-noun naming convention. In Windows PowerShell, the verbs indicate an action to perform, such as &lt;b&gt;Set&lt;/b&gt; to make a change or &lt;b&gt;Get&lt;/b&gt; to retrieve a value. The noun indicates the item with which to work such as a process or a service. By mastering the verb-noun naming convention, you can quickly hypothesize what a prospective command might be called. For example, if you need to obtain information about a process, and you know that Windows PowerShell uses the verb &lt;b&gt;Get&lt;/b&gt; &amp;nbsp;to retrieve information, you surmise that the command might very well be &lt;b&gt;Get-Process&lt;/b&gt;. To obtain information about services you try &lt;b&gt;Get-Service&lt;/b&gt;&amp;hellip;and once again you are correct.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Note&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/b&gt;When &amp;ldquo;guessing&amp;rdquo; Windows PowerShell cmdlet names, always try the singular form first. Windows PowerShell prefers the singular form of nouns. It is not a design requirement, but it is a strong preference. Therefore, the cmdlets are named &lt;b&gt;Get-Service&lt;/b&gt;, &lt;b&gt;Get-Process&lt;/b&gt;, not &lt;b&gt;Get-Services&lt;/b&gt; or &lt;b&gt;Get-Processes&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;To see the list of approved verbs, use the &lt;b&gt;Get-Verb&lt;/b&gt; cmdlet. 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/6735.hsg_2D00_5_2D00_14_2D00_12_2D00_01.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/6735.hsg_2D00_5_2D00_14_2D00_12_2D00_01.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;There are nearly 100 approved verbs in Windows PowerShell&amp;nbsp;2.0. This is shown in the command that follows where the &lt;b&gt;Measure-Object&lt;/b&gt; cmdlet returns the count of verbs.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; (get-verb | Measure-Object).count&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;96&lt;/p&gt;
&lt;h2&gt;Analyzing Windows PowerShell verb grouping&lt;/h2&gt;
&lt;p&gt;With nearly 100 verbs, you may be asking yourself, &amp;ldquo;How does an array of 100 verbs assist in learning Windows PowerShell?&amp;rdquo; You would be justified in asking that question. Nearly 100 different and unrelated items are really difficult to learn. However, the Windows PowerShell team grouped the verbs. For example, analyzing the common verbs reveals a pattern. The common verbs are listed here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; Get-Verb | where { $_.group -match 'common'} | Format-Wide verb -AutoSize&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Add&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Clear&amp;nbsp; Close&amp;nbsp; Copy&amp;nbsp;&amp;nbsp; Enter&amp;nbsp; Exit&amp;nbsp;&amp;nbsp; Find&amp;nbsp;&amp;nbsp; Format Get&amp;nbsp;&amp;nbsp;&amp;nbsp; Hide&amp;nbsp;&amp;nbsp; Join&amp;nbsp;&amp;nbsp; Lock&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Move&amp;nbsp;&amp;nbsp;&amp;nbsp; New&amp;nbsp;&amp;nbsp;&amp;nbsp; Open&amp;nbsp;&amp;nbsp; Pop&amp;nbsp;&amp;nbsp;&amp;nbsp; Push&amp;nbsp;&amp;nbsp; Redo&amp;nbsp;&amp;nbsp; Remove Rename Reset&amp;nbsp; Search Select Set&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Show&amp;nbsp;&amp;nbsp;&amp;nbsp; Skip&amp;nbsp;&amp;nbsp; Split&amp;nbsp; Step&amp;nbsp;&amp;nbsp; Switch Undo&amp;nbsp;&amp;nbsp; Unlock Watch&lt;/p&gt;
&lt;p&gt;The pattern for the verbs emerges when you analyze the verbs, for example: Add/Remove, Enter/Exit, Get/Set, Select/Skip, Lock/Unlock, Push/Pop, and so on. By learning the pattern to the common verbs, you quickly gain a handle on the Windows PowerShell naming convention.&lt;/p&gt;
&lt;p&gt;By using the Windows PowerShell verb grouping, you can determine where to focus your efforts. The following command lists the Windows PowerShell verb grouping.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; Get-Verb | select group -Unique&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Group&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;-----&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Common&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Data&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Lifecycle&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Diagnostic&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Communications&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Security&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Other&lt;/p&gt;
&lt;h2&gt;Analyzing Windows PowerShell verb distribution&lt;/h2&gt;
&lt;p&gt;Another way to get a better handle on the Windows PowerShell cmdlets is to analyze the verb distribution. Although there are nearly 100 approved verbs (not to mention unapproved verbs that are used by rogue developers), only a fraction of them are utilized repeatedly, and some of them are not used at all in a standard Windows PowerShell installation. By using the &lt;b&gt;Group-Object&lt;/b&gt; (&lt;b&gt;group&lt;/b&gt; is an alias) and the &lt;b&gt;Sort-Object&lt;/b&gt; cmdlets (&lt;b&gt;sort&lt;/b&gt; is an alias), the distribution of the cmdlets quickly becomes evident. The following command shows the verb distribution.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-Command -CommandType cmdlet | group verb | sort count &amp;ndash;Descending&lt;/p&gt;
&lt;p&gt;The command and the output associated with the command are 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/3173.hsg_2D00_5_2D00_14_2D00_12_2D00_02.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3173.hsg_2D00_5_2D00_14_2D00_12_2D00_02.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The preceding output makes it clear that most cmdlets only use a few of the verbs. In fact, most of the cmdlets use one of only 10 verbs. This is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; Get-Command -CommandType cmdlet | group verb | sort count -Descending | selec&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;t -First 10&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Count Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Group&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;&amp;nbsp;&amp;nbsp; 46 Get&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {Get-Acl, Get-Alias, Get-AuthenticodeSignature, G...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp; 19 Set&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{Set-Acl, Set-Alias, Set-AuthenticodeSignature, S...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp; 17 New&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {New-Alias, New-Event, New-EventLog, New-Item...}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp; 14 Remove&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {Remove-Computer, Remove-Event, Remove-EventLog, ...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8 Export&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {Export-Alias, Export-Clixml, Export-Console, Exp...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8 Write&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {Write-Debug, Write-Error, Write-EventLog, Write-...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7 Import&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {Import-Alias, Import-Clixml, Import-Counter, Imp...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7 Out&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {Out-Default, Out-File, Out-GridView, Out-Host...}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6 Add&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {Add-Computer, Add-Content, Add-History, Add-Memb...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6 Start&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {Start-Job, Start-Process, Start-Service, Start-S...&lt;/p&gt;
&lt;p&gt;In fact, of 236 cmdlets, 138 of the cmdlets use one of only 10 different verbs. This is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; (Get-Command -CommandType cmdlet | measure).count&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;236&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; $count = 0 ; Get-Command -CommandType cmdlet | group verb | sort count -Descending |&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;select -First 10 | % {$count += $_.count ; $count}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;46&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;65&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;82&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;96&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;104&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;112&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;119&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;126&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;132&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;138&lt;/p&gt;
&lt;p&gt;Therefore, GB, all you need to do is to master 10 verbs and you will have a good handle on more than half of the cmdlets that ship with Windows PowerShell&amp;nbsp;2.0. Join me tomorrow when I will talk about more cool Windows PowerShell stuff.&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;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&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=3497569" 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/getting+started/">getting started</category></item><item><title>Weekend Scripter: Ten Ways to Continue the Spirit of the PowerShell Scripting Games</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/13/weekend-scripter-ten-ways-to-continue-the-spirit-of-the-powershell-scripting-games.aspx</link><pubDate>Sun, 13 May 2012 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3497566</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3497566</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/13/weekend-scripter-ten-ways-to-continue-the-spirit-of-the-powershell-scripting-games.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Microsoft Scripting Guy, Ed Wilson, answers the question about how to continue with the spirit of the Scripting Games.&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. I know it is the weekend, at least in Charlotte, North Carolina in the southern portion of the United States. But hey, I have been really busy this week, and I am behind on answering email sent to &lt;a href="mailto:scripter@microsoft.com"&gt;scripter@microsoft.com&lt;/a&gt;. So, I thought I would take today to answer one of my emails. Here we go&amp;hellip;&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! I have to tell you that I am sort of in a daze. In fact, you might even say that I am becoming depressed. The reason? The 2012 Scripting Games are over, and I do not know what to do with all my spare time. I was used to going to work every day and checking out the Hey, Scripting Guy! Blog, reading about the Scripting Wife, keeping track of all the comments on the blogs and twitter&amp;hellip;and now it is all over. Can you do another Scripting Games? I have really taken my Windows PowerShell to the next level, and I do not want to lose that momentum. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;mdash;EB&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&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 EB,&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. I can tell you for a fact, there will not be another Scripting Games this year. We will probably do one again next year, but it took me more than six months of planning for this year&amp;rsquo;s games, and it would be impossible to do that more than once a year. In addition to my time and efforts, more than 60 Microsoft employees, Microsoft MVPs, and other IT Pros rolled up their sleeves and pitched in to assist with grading and writing expert commentaries and blogs. The Scripting Games are a big deal, and they involve lots of work by lots of people.&lt;/p&gt;
&lt;p&gt;So, EB, what can you do to continue the spirit of the Scripting Games? There are a number of ways to do this. In no particular order, here is a list.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Join a local Windows PowerShell User Group. There is a master list of Windows PowerShell User Groups on the &lt;a href="http://www.powershellgroup.org/" target="_blank"&gt;PowerShell Community Groups site&lt;/a&gt;. It lists user groups all over the world. There is even a virtual user group if a group does not exist in your area. Better yet, if a Windows PowerShell User Group does not exist in your area, start one. I have written about &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/tags/community/" target="_blank"&gt;Windows PowerShell User Groups&lt;/a&gt; on several occasions. In one blog, Microsoft MVP, Tome Tanasovski, discussed &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2010/10/15/tap-into-the-powershell-community-for-fun-and-education.aspx" target="_blank"&gt;why you might want to join a user group&lt;/a&gt;. Suffice it to say, joining a local Windows PowerShell User Group is a great way to continue the education you began with the Scripting Games.&lt;/li&gt;
&lt;li&gt;Follow the #PowerShell tag on Twitter. Many Windows PowerShell MVPs and other Windows PowerShell community leaders use Twitter, and they all (including the Scripting Wife and me) follow the #PowerShell tag. When you develop a large circle of friends on Twitter, you can quickly become overwhelmed by messages. By using a Twitter client (I am currently using MetroTwit, which sports a nice clean Windows Metro-type interface), you can create search columns that filter out tweets by search tags that people include in the messages. This is great when I am using the Twitter client on my Windows&amp;nbsp;7 Smartphone. On Twitter, you will see various people mention blogs about Windows PowerShell, videos that they have uploaded, Windows PowerShell User Group meetings, in addition to the general give-and-take of people asking questions. It is a great way to become engaged in the community. By the way, my twitter handle is &lt;a href="http://twitter.com/#!/scriptingguys/"&gt;@ScriptingGuys&lt;/a&gt;, and the Scripting Wife&amp;rsquo;s handle is &lt;a href="http://twitter.com/#!/scriptingwife"&gt;@ScriptingWife&lt;/a&gt;. We would love for you to follow us.&lt;/li&gt;
&lt;li&gt;Join the &lt;a href="http://bit.ly/scriptingguysfacebook" target="_blank"&gt;Scripting Guys Group&lt;/a&gt; on Facebook. There are over three-thousand members in that group, and it is a great way to interact with people who have similar interests.&lt;/li&gt;
&lt;li&gt;Become active in the &lt;a href="http://social.technet.microsoft.com/Forums/en/ITCG/threads/" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;. I talked about the value of becoming active in the forum in a blog that I wrote about &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2009/09/07/hey-scripting-guy-september-7-2009.aspx" target="_blank"&gt;how to learn Windows PowerShell&lt;/a&gt;. I gave an example from when I was first studying for the MCSE certification, but the lesson is still applicable. The forum is a great place to ask questions, and also a great place to learn Windows PowerShell better by helping others. There is an old adage (which is true), and it goes like this: &amp;ldquo;The best way to learn a subject is to teach it.&amp;rdquo; Answering questions on the Scripting Guys Forum is teaching&amp;mdash;and a great way to learn.&lt;/li&gt;
&lt;li&gt;Share scripts on the &lt;a href="http://gallery.technet.microsoft.com/ScriptCenter/" target="_blank"&gt;Scripting Guys Script Repository&lt;/a&gt;. When you have shared a script with the world on the Scripting Guys Script Repository, you have entered an elite world of scripters because you are now giving back to the scripting community in a real and substantial way. It is also fun because now you get to see how well your script is received by the community. Hey, maybe it will become a &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/01/02/find-the-top-ten-scripts-submitted-to-the-script-repository.aspx" target="_blank"&gt;Top Ten Script&lt;/a&gt; and be mentioned by me in a Hey, Scripting Guy! Blog.&lt;/li&gt;
&lt;li&gt;Watch the &lt;a href="http://powerscripting.wordpress.com/" target="_blank"&gt;PowerScripting Podcast&lt;/a&gt;. The PowerScripting Podcast is a weekly podcast about Windows PowerShell that is recorded with a live audience. It is a lot of fun, and the interaction in the chat room makes it an enjoyable and substantial learning experience. The Scripting Wife does the scheduling for Microsoft MVP, Hal Rottenberg, and cohost, Jonathan Walz; and therefore, she is in the chat room each week. The advantage of recording live is that you have a chance to ask questions of the host via the chat room. Check it out.&lt;/li&gt;
&lt;li&gt;Check out the &lt;a href="http://technet.microsoft.com/en-us/scriptcenter/dd742419.aspx" target="_blank"&gt;Scripting with Windows PowerShell site&lt;/a&gt; in the Scripting Guys Script Center. This site hosts a number of podcasts and two video series with associated quizzes that comprise a number of learning opportunities.&lt;/li&gt;
&lt;li&gt;Peruse the &lt;a href="http://technet.microsoft.com/en-us/scriptcenter/hh182567" target="_blank"&gt;Scripting Community site&lt;/a&gt;. I list all of my upcoming appearances there. There is also an interactive map of Windows PowerShell User Groups in the U.S. and other resources.&lt;/li&gt;
&lt;li&gt;Read a book about Windows PowerShell. There are a number of very good books about Windows PowerShell on the market. Each book has a different emphasis, and I own many of the current releases. One of the things I hit pretty hard in the Scripting Games this year was Windows PowerShell best practices. Therefore, you may want to get a copy of my &lt;a href="http://www.amazon.com/Windows-PowerShell-2-0-Best-Practices/dp/0735626464/ref=sr_1_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1255959455&amp;amp;sr=8-1"&gt;Windows PowerShell&amp;nbsp;2.0 Best Practices&lt;/a&gt; book. It was published by Microsoft Press, and it includes hundreds of scripts and dozens of sidebars written by the Windows PowerShell product group at Microsoft and the Windows PowerShell community. (By the way, if you are coming to &lt;a href="http://northamerica.msteched.com/?mtag=scriptingguys#fbid=fhdzoB_96iS" target="_blank"&gt;TechEd 2012 in Orlando&lt;/a&gt;, I will be hosting the Windows PowerShell Best Practices &amp;ldquo;birds of a feather&amp;rdquo; session with cohost, Windows PowerShell MVP, Don Jones. It will be a great session.)&lt;/li&gt;
&lt;li&gt;Read the &lt;a href="http://blogs.technet.com/b/heyscriptingguy/" target="_blank"&gt;Hey, Scripting Guy! Blog&lt;/a&gt; on a daily basis. The Hey, Scripting Guy! Blog is one of the few blogs that publishes seven days a week, 365 days a year. This provides a substantial amount of new information about Windows PowerShell. In addition to being written in a causal and witty style, the content is excellent (if I do say so myself). Make it your Home page so you do not miss a single episode. &amp;nbsp;&lt;/li&gt;
&lt;/ol&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;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3497566" 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/getting+started/">getting started</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/community/">community</category></item><item><title>Weekend Scripter: Use PowerShell to Easily Modify Registry Property Values</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/12/weekend-scripter-use-powershell-to-easily-modify-registry-property-values.aspx</link><pubDate>Sat, 12 May 2012 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3497553</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3497553</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/12/weekend-scripter-use-powershell-to-easily-modify-registry-property-values.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;:&amp;nbsp;Microsoft Scripting Guy, Ed Wilson, shows to use the PowerShell registry provider to easily modify registry property values.&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. It is finally the weekend. It seems like it has been a rather long week. Of course, each week is only 168 hours long, but this one has seemed long. It is due in part to the travel for recent conferences, various meetings, and an unexpected dinner with Windows PowerShell tweeps. It has been raining quite a bit this week, and the air outside has a fresh spring rain smell to it. I am sitting on the lanai sipping a cup of Irish Breakfast tea and munching on a blueberry scone that the Scripting Wife made last night. I have set aside most of today to work on my &lt;a href="http://www.amazon.com/Windows-PowerShell-3-0-Step/dp/0735663394/ref=sr_1_4?ie=UTF8&amp;amp;qid=1336593704&amp;amp;sr=8-4" target="_blank"&gt;Windows PowerShell&amp;nbsp;3.0 Step-by-Step&lt;/a&gt; book that will be published this summer with Microsoft Press. (Cool! I just noticed that you can preorder it on Amazon.)&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Note&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;This is the sixth blog in a series of Hey, Scripting Guy! Blogs that discuss using the Registry provider. The first blog, &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/07/use-the-powershell-registry-provider-to-simplify-registry-access.aspx" target="_blank"&gt;Using the Registry Provider to Simply Registry Access&lt;/a&gt;&lt;i&gt; &lt;/i&gt;posted on Monday. Tuesday I discussed &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/08/use-powershell-to-back-up-system-state-prior-to-making-changes.aspx" target="_blank"&gt;using the *restore* cmdlets&lt;/a&gt; to perform a system state backup of a computer prior to manipulating the registry. On Wednesday I talked about &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/09/use-powershell-to-easily-create-new-registry-keys.aspx" target="_blank"&gt;creating new registry keys and assigning default values&lt;/a&gt;. In the fourth blog, I talked about &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/10/use-powershell-to-create-new-registry-keys-on-remote-systems.aspx" target="_blank"&gt;creating new registry keys on remote computer systems&lt;/a&gt;. I also discussed creating registry property values. In the fifth blog, I created a function and a script that &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/11/use-powershell-to-enumerate-registry-property-values.aspx" target="_blank"&gt;enumerate all the registry properties and their associated values&lt;/a&gt;. The function and script return a custom object that permits further work with the output by using standard Windows PowerShell functionality. For additional information about working with the registry via Windows PowerShell, &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/tags/windows+powershell/operating+system+/registry/" target="_blank"&gt;see this collection of blogs&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Modifying the value of a registry property value&lt;/h2&gt;
&lt;p&gt;To modify the value of a registry property value requires using the &lt;b&gt;Set-PropertyItem&lt;/b&gt; cmdlet.&lt;/p&gt;
&lt;p&gt;Only the steps&amp;hellip;&lt;/p&gt;
&lt;p&gt;Modifying the value of a registry property value:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Use the &lt;b&gt;Push-Location&lt;/b&gt; cmdlet to save the current working location.&lt;/li&gt;
&lt;li&gt;Use the &lt;b&gt;Set-Location&lt;/b&gt; cmdlet to change to the appropriate registry drive.&lt;/li&gt;
&lt;li&gt;Use the &lt;b&gt;Set-ItemProperty&lt;/b&gt; cmdlet to assign a new value to the registry property.&lt;/li&gt;
&lt;li&gt;Use the &lt;b&gt;Pop-Location&lt;/b&gt; cmdlet to return to the original working location.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;In the image that follows, a registry key named &lt;b&gt;hsg&lt;/b&gt; exists in the HKCU:\Software hive. The registry key has a property named &lt;b&gt;NewProperty&lt;/b&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/5773.hsg_2D00_5_2D00_12_2D00_12_2D00_01.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/5773.hsg_2D00_5_2D00_12_2D00_12_2D00_01.png" alt="Image of Registry Editor" title="Image of Registry Editor" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;When you know that a registry property value exists, the solution is really simple. You use the &lt;b&gt;Set-ItemProperty&lt;/b&gt; cmdlet and assign a new value. The code that follows saves the current working location, changes the new working location to the &lt;b&gt;hsg&lt;/b&gt; registry key, uses the &lt;b&gt;Set-ItemProperty&lt;/b&gt; cmdlet to assign new values, and then uses the &lt;b&gt;Pop-Location&lt;/b&gt; cmdlet to return to the original working location.&lt;/p&gt;
&lt;p&gt;The code that follows relies on positional parameters for the &lt;b&gt;Set-ItemProperty&lt;/b&gt; cmdlet. The first parameter is &lt;i&gt;Path&lt;/i&gt;. Because the &lt;b&gt;Set-Location&lt;/b&gt; cmdlet sets the working location to the &lt;b&gt;hsg&lt;/b&gt; registry key, a period identifies the path as the current directory. The second parameter is the &lt;i&gt;Name &lt;/i&gt;of the registry property to change. In this example, it is &lt;b&gt;NewProperty&lt;/b&gt;. The last parameter is &lt;i&gt;Value, &lt;/i&gt;and that defines the value to assign to the registry property. In this example, it is &lt;b&gt;mynewvalue&lt;/b&gt;. Thus, the command with complete parameter names would be:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Set-ItemProperty -Path . -Name newproperty -Value mynewvalue. The quotation marks in the code that follows are not required, but they do not harm anything either.&lt;/p&gt;
&lt;p&gt;Here is the code:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; Push-Location&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; Set-Location HKCU:\Software\hsg&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS HKCU:\Software\hsg&amp;gt; Set-ItemProperty . newproperty "mynewvalue"&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS HKCU:\Software\hsg&amp;gt; Pop-Location&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt;&lt;/p&gt;
&lt;p&gt;Of course, all the pushing and popping and setting of locations are not really required. It is entirely possible to change the registry property value from any location within the Windows PowerShell provider subsystem.&lt;/p&gt;
&lt;p&gt;Only the step&amp;hellip;&lt;/p&gt;
&lt;p&gt;The short way to change a registry property value:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Use the &lt;b&gt;Set-ItemProperty&lt;/b&gt; cmdlet to assign a new value. Ensure that you specify the complete path to the registry key.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Here is an example of using the &lt;b&gt;Set-ItemProperty &lt;/b&gt;cmdlet to change a registry property value without first navigating to the registry drive.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; Set-ItemProperty -Path HKCU:\Software\hsg -Name newproperty -Value anewvalue&lt;/p&gt;
&lt;h2&gt;Dealing with a missing registry property value&lt;/h2&gt;
&lt;p&gt;If you need to set a registry property value, you can set the value of that property easily by using the &lt;b&gt;Set-ItemProperty &lt;/b&gt;cmdlet. But what if the registry property does not exist? How do you set the property value then? You can still use the &lt;b&gt;Set-ItemProperty&lt;/b&gt; cmdlet to set a registry property value, even if the registry property does not exist.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Set-ItemProperty -Path HKCU:\Software\hsg -Name missingproperty -Value avalue&lt;/p&gt;
&lt;p&gt;To determine if a registry key exists is easy: Use the &lt;b&gt;Test-Path&lt;/b&gt; cmdlet. It returns True if the key exists and False if it does not exist. This technique is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; Test-Path HKCU:\Software\hsg&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;True&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; Test-Path HKCU:\Software\hsg\newproperty&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;False&lt;/p&gt;
&lt;p&gt;But unfortunately, this technique does not work for a registry key property. It always returns False&amp;mdash;even if the registry property exists. This is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; Test-Path HKCU:\Software\hsg\newproperty&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;False&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; Test-Path HKCU:\Software\hsg\bogus&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;False&lt;/p&gt;
&lt;p&gt;Therefore, if you do not want to overwrite a registry key property if it already exists, you need a way to determine if the registry key property exists&amp;mdash;and using the &lt;b&gt;Test-Path&lt;/b&gt; cmdlet does not work.&lt;/p&gt;
&lt;p&gt;One of the cool things about writing the Hey, Scripting Guy! Blog is the interaction with the readers. One such reader, Richard, mentioned the problem of using &lt;b&gt;Test-Path&lt;/b&gt; to determine if a registry property exists prior to calling the &lt;b&gt;Set-ItemProperty&lt;/b&gt;. This is the technique he suggested, and it works great.&lt;/p&gt;
&lt;p&gt;Only the steps&amp;hellip;&lt;/p&gt;
&lt;p&gt;Testing for a registry key property prior to writing a new value:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Use the &lt;i&gt;if &lt;/i&gt;statement and the &lt;b&gt;Get-ItemProperty&lt;/b&gt; cmdlet to retrieve the value of the registry key property. Specify &lt;i&gt;erroraction &lt;/i&gt;(&lt;i&gt;ea &lt;/i&gt;is an alias) of S&lt;i&gt;ilentlyContinue &lt;/i&gt;(0 is the enumeration value).&lt;/li&gt;
&lt;li&gt;In the script block for the &lt;i&gt;if &lt;/i&gt;statement, display a message that the registry property exists, or simply exit.&lt;/li&gt;
&lt;li&gt;In the &lt;i&gt;else &lt;/i&gt;statement, call the &lt;b&gt;Set-ItemProperty&lt;/b&gt; to create and to set the value of the registry key property.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This technique is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;if((Get-ItemProperty HKCU:\Software\hsg -Name bogus -ea 0).bogus) {'Propertyalready exists'}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;ELSE { Set-ItemProperty -Path HKCU:\Software\hsg -Name bogus -Value'initial value'}&lt;/p&gt;
&lt;p&gt;The use of this technique appears in the image that follows. The first time, the bogus registry key property value does not exist and it is created. The second time, the registry key property already exists and a message to that effect appears.&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/6558.hsg_2D00_5_2D00_12_2D00_12_2D00_02.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/6558.hsg_2D00_5_2D00_12_2D00_12_2D00_02.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Well, this concludes Registry Week. Tomorrow, I answer a question about how to continue with the spirit of the Scripting Games.&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;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&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=3497553" 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/registry/">registry</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/operating+system+/">operating system </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/getting+started/">getting started</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Weekend+Scripter/">Weekend Scripter</category></item><item><title>Use PowerShell to Enumerate Registry Property Values</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/11/use-powershell-to-enumerate-registry-property-values.aspx</link><pubDate>Fri, 11 May 2012 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3497231</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=3497231</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/11/use-powershell-to-enumerate-registry-property-values.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Microsoft Scripting Guy, Ed Wilson, shows how to use Windows PowerShell to enumerate all the properties and their values under a registry key.&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! I have a question. It seems that getting the property values under a registry key is a tedious process. It looks like I need to know the exact property value to find out its value. Often I do not have this information. I would like a way to say, &amp;ldquo;Just give me the property values and their associated value.&amp;rdquo; I do not want to do a lot of work to get this information. Is it possible?&lt;/p&gt;
&lt;p&gt;&amp;mdash;BW&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 BW,&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. I just checked on the status of an order of Monkey Picked Oolong Tea that the Scripting Wife ordered for me. It arrives tomorrow. Charlotte, North Carolina in the United States is not a huge tea market&amp;mdash;but hey, I have great Internet access at home and that gives me access to some of the best tea brokers in the world. I first ran across Monkey Picked tea in a small tearoom while the Scripting Wife and I were on our way to the &lt;a href="http://minasiconference.wordpress.com/" target="_blank"&gt;Mark Minasi Conference&lt;/a&gt;. I had the Monkey Picked Oolong; she had hot chocolate. But she remembered how much I kept going on and on about the light and delicate flavor, and next thing I know, we have a package arriving tomorrow.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Note&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;This is the fifth blog in a series of Hey, Scripting Guy! Blogs that discuss using the Registry provider. The first blog, &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/07/use-the-powershell-registry-provider-to-simplify-registry-access.aspx" target="_blank"&gt;Using the Registry Provider to Simply Registry Access&lt;/a&gt;&lt;i&gt; &lt;/i&gt;posted on Monday. Tuesday I discussed &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/08/use-powershell-to-back-up-system-state-prior-to-making-changes.aspx" target="_blank"&gt;using the *restore* cmdlets&lt;/a&gt; to perform a system state backup of a computer prior to manipulating the registry. On Wednesday I talked about &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/09/use-powershell-to-easily-create-new-registry-keys.aspx" target="_blank"&gt;creating new registry keys and assigning default values&lt;/a&gt;. In the fourth blog, I talked about &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/10/use-powershell-to-create-new-registry-keys-on-remote-systems.aspx" target="_blank"&gt;creating new registry keys on remote computer systems&lt;/a&gt;. I also discussed creating registry property values. For additional information about working with the registry via Windows PowerShell, &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/tags/windows+powershell/operating+system+/registry/" target="_blank"&gt;see this collection of blogs&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Working with registry property values&lt;/h2&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Note&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; For a VBScript version of this blog, see &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2008/04/08/how-can-i-retrieve-all-the-values-in-a-registry-key.aspx" target="_blank"&gt;Hey, Scripting Guy! How Can I Retrieve All the Values in a Registry Key?&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Because of the hierarchical nature of the registry in Windows, the file system metaphor sort of breaks down. On a file system drive, you can use the &lt;b&gt;New-Item&lt;/b&gt; cmdlet to create a folder (directory), and then go back and create a file inside the folder by using the same cmdlet. With the registry, that is not the case. &lt;b&gt;New-Item&lt;/b&gt; creates the registry keys, but it is the &lt;b&gt;New-ItemProperty&lt;/b&gt; cmdlet that creates the properties that are associated with the registry keys. This concept 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/6305.hsg_2D00_5_2D00_11_2D00_12_2D00_01.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/6305.hsg_2D00_5_2D00_11_2D00_12_2D00_01.png" alt="Image of Registry Editor" title="Image of Registry Editor" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Yesterday&amp;rsquo;s Hey, Scripting Guy! Blog talked about &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/10/use-powershell-to-create-new-registry-keys-on-remote-systems.aspx" target="_blank"&gt;retrieving registry properties&lt;/a&gt;. In that blog, I discussed using the &lt;b&gt;Get-ItemProperty&lt;/b&gt; cmdlet to retrieve registry property values, in addition to the specific registry property value value. (I know, it gets a little redundant). But as you pointed out, BW, from the perspective of perusing preset registry values, knowing an exact registry property value name is not the most efficient way of doing things.&lt;/p&gt;
&lt;h2&gt;Enumerating registry property values&lt;/h2&gt;
&lt;p&gt;The image that follows illustrates the &lt;i&gt;Winlogon &lt;/i&gt;registry key. This registry key has four registry properties (in addition to the &lt;i&gt;Default&lt;/i&gt; registry property, which is not set in this example).&lt;i&gt; &lt;/i&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/5756.hsg_2D00_5_2D00_11_2D00_12_2D00_02.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/5756.hsg_2D00_5_2D00_11_2D00_12_2D00_02.png" alt="Image of Registry Editor" title="Image of Registry Editor" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;There are several steps involved in obtaining the value of the registry property values under a specific registry key.&lt;/p&gt;
&lt;p&gt;Only the steps&amp;hellip;&lt;/p&gt;
&lt;p&gt;Enumerating registry property values:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Use the &lt;b&gt;Push-Location&lt;/b&gt; cmdlet to store the current working location.&lt;/li&gt;
&lt;li&gt;Use the &lt;b&gt;Set-Location&lt;/b&gt; cmdlet to change the current working location to the appropriate registry drive.&lt;/li&gt;
&lt;li&gt;Use the &lt;b&gt;Get-Item&lt;/b&gt; cmdlet to retrieve the properties of the registry key.&lt;/li&gt;
&lt;li&gt;Pipe the registry properties through the &lt;b&gt;ForEach-Object&lt;/b&gt; cmdlet.&lt;/li&gt;
&lt;li&gt;In the script block of the &lt;b&gt;ForEach-Object&lt;/b&gt; cmdlet, use the &lt;b&gt;Get-ItemProperty&lt;/b&gt; cmdlet to retrieve the property values.&lt;/li&gt;
&lt;li&gt;Return to the original working location by using the &lt;b&gt;Pop-Location&lt;/b&gt; cmdlet.&lt;/li&gt;
&lt;/ol&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Note&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; When you are typing the path to the specific registry key, remember that you can use tab expansion. The use of the Windows PowerShell tab expansion feature not only saves time typing, but it also invariably saves time troubleshooting mistyped commands. It is essential that you train yourself to use tab expansion everywhere it is available.&lt;/p&gt;
&lt;p&gt;The Get-RegistryKeyPropertiesAndValues.ps1 script follows the previous &lt;i&gt;Enumerating registry property values &lt;/i&gt;steps, but it adds a bit of extra power to the equation by creating a custom object for each registry property/value combination. The script creates a new custom object for each key/property pair. To do this, the script creates the object inside the &lt;b&gt;Foreach-Object&lt;/b&gt; cmdlet. The resulting object pipes to the &lt;b&gt;Format-Table&lt;/b&gt; for display to the console. The script then returns to the original working location by using the &lt;b&gt;Pop-Location&lt;/b&gt; cmdlet. The complete Get-RegistryKeyPropertiesAndValues.ps1 script is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-RegistryKeyPropertiesAndValues.ps1&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Push-Location&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Set-Location 'HKCU:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon'&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-Item . |&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Select-Object -ExpandProperty property |&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;ForEach-Object {&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;New-Object psobject -Property @{"property"=$_;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp; "Value" = (Get-ItemProperty -Path . -Name $_).$_}} |&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Format-Table property, value -AutoSize&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Pop-Location&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;It is rather easy to convert the above script to a function. The Get-RegistryKeyPropertiiesAndValues function appears here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-RegistryKeyPropertiesAndValues Function&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Function Get-RegistryKeyPropertiesAndValues&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 accepts a registry path and returns all reg key properties and values&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 returns registry key properies and values.&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; Get-RegistryKeyPropertiesAndValues -path 'HKCU:\Volatile Environment'&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Returns all of the registry property values under the \volatile environment key&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp; .Parameter path&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; The path to the registry key&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; Get-RegistryKeyPropertiesAndValues&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/09/2012 15:18:41&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; KEYWORDS: Operating System, Registry, Scripting Techniques, Getting Started&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; HSG: 5-11-12&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/blog&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;Param(&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; [Parameter(Mandatory=$true)]&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp; [string]$path)&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;Push-Location&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;Set-Location -Path $path&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;Get-Item . |&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;Select-Object -ExpandProperty property |&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;ForEach-Object {&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;New-Object psobject -Property @{"property"=$_;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Value" = (Get-ItemProperty -Path . -Name $_).$_}}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;Pop-Location&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;} #end function Get-RegistryKeyPropertiesAndValues&lt;/p&gt;
&lt;p&gt;To use the &lt;b&gt;Get-RegistryKeyPropertiesAndValues&lt;/b&gt; function to obtain registry key properties and their associated values, pass the path to it. For example, the image that follows illustrates the &lt;i&gt;Volatile Environment &lt;/i&gt;registry key. On the right are a large number of registry key properties.&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/3644.hsg_2D00_5_2D00_11_2D00_12_2D00_03.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3644.hsg_2D00_5_2D00_11_2D00_12_2D00_03.png" alt="Image of Registry Editor" title="Image of Registry Editor" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Open the Windows PowerShell ISE and load the function by opening the script that contains it. Next load the function into memory by clicking the run button (or pressing F5). When it is loaded into memory, call the function by typing the function name in the immediate window and providing a path to a specific registry key. For this example, use the HKCU:\Volatile Environment registry key (make sure you put quotation marks around the entire path to the registry key). Use the &lt;b&gt;Format-Table&lt;/b&gt; cmdlet to display the property name and then the property value. The following command illustrates a typical command line.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-RegistryKeyPropertiesAndValues -path 'HKCU:\Volatile Environment' | ft property, value -AutoSize&lt;/p&gt;
&lt;p&gt;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/8831.hsg_2D00_5_2D00_11_2D00_12_2D00_04.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8831.hsg_2D00_5_2D00_11_2D00_12_2D00_04.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;BW, that is all there is to obtaining the value of the registry property values under a specific registry key. Registry Week will continue tomorrow when I will talk about modifying registry property values.&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;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&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=3497231" 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/registry/">registry</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/operating+system+/">operating system </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/getting+started/">getting started</category></item><item><title>Use PowerShell to Create New Registry Keys on Remote Systems</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/10/use-powershell-to-create-new-registry-keys-on-remote-systems.aspx</link><pubDate>Thu, 10 May 2012 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3496993</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=3496993</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/10/use-powershell-to-create-new-registry-keys-on-remote-systems.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Learn how to use Windows PowerShell to create new registry keys on remote systems by using remoting.&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! I need to create registry keys on a number of remote servers. I do not want to use the Registry Editor to do this because the servers all have the firewall enabled, and I do not want to enable the remote registry service on these machines. Is there a way I can use Windows PowerShell to create these registry keys? I really do not want to use remote desktop to do this.&lt;/p&gt;
&lt;p&gt;&amp;mdash;YH&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 YH,&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. I just finished a team meeting where we were talking about documentation for the Windows Server &amp;ldquo;8&amp;rdquo; Beta release&amp;mdash;really exciting stuff. I can tell you that Microsoft is the most exciting company for which I have ever worked. It is everything I hoped for when I joined nearly 11 years ago&amp;mdash;and even more. I am dying to start writing about Windows PowerShell&amp;nbsp;3.0 and Windows Server &amp;ldquo;8&amp;rdquo; Beta, but I imagine that most IT Pros have not yet deployed it to their systems, so I will forgo that until the product actually ships.&lt;/p&gt;
&lt;p&gt;I am sipping a cup of &lt;a href="http://en.wikipedia.org/wiki/Darjeeling_tea" target="_blank"&gt;Darjeeling tea&lt;/a&gt; with some lemon grass and a cinnamon stick, accompanied by a slice of 90 percent cacao chocolate. It is the perfect afternoon snack. This week is turning out to be a lot of fun. Tonight, the Scripting Wife and I are having dinner with one of the members of the Charlotte Windows PowerShell Users Group. We will be talking about upcoming user group presentations. It is always a lot of fun to get together with fellow Windows PowerShell geeks because the conversations are usually $cool.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Note&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;This is the third blog in a series of Hey, Scripting Guy! Blogs that discuss using the Registry provider. The first blog, &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/07/use-the-powershell-registry-provider-to-simplify-registry-access.aspx" target="_blank"&gt;Use the Registry Provider to Simply Registry Access&lt;/a&gt;&lt;i&gt;,&amp;nbsp;&lt;/i&gt;posted on Monday. Tuesday I discussed &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/08/use-powershell-to-back-up-system-state-prior-to-making-changes.aspx" target="_blank"&gt;using the *restore* cmdlets&lt;/a&gt; to perform a system state backup of a computer prior to manipulating the registry. On Wednesday I talked about &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/09/use-powershell-to-easily-create-new-registry-keys.aspx" target="_blank"&gt;creating new registry keys and assigning default values&lt;/a&gt;. For additional information about working with the registry via Windows PowerShell, &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/tags/windows+powershell/operating+system+/registry/" target="_blank"&gt;see this collection of blogs&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;YH, there are several ways to create registry keys on remote systems. One way is to use the .NET Framework classes and another way is to use WMI. By far, the easiest way is to combine using the Windows PowerShell Registry provider with Windows PowerShell remoting. This is because Windows PowerShell remoting uses the firewall friendly WSMan protocol. In fact, inside a single forest, single domain with Windows Server &amp;ldquo;8&amp;rdquo; Beta, remoting just works. There are no configuration changes required to enable Windows PowerShell remoting in Windows Server &amp;ldquo;8&amp;rdquo; Beta.&lt;/p&gt;
&lt;h2&gt;Entering a remote session to create a new registry key&lt;/h2&gt;
&lt;p&gt;If you only have a single computer upon which you need to create one or more new registry keys, it is probably easiest to enter a remote Windows PowerShell session. Doing this provides you with the equivalent experience of opening the Windows PowerShell console and working in an interactive fashion. There are several steps involved, but they are not too difficult.&lt;/p&gt;
&lt;p&gt;Only the steps&amp;hellip;&lt;/p&gt;
&lt;p&gt;Entering a remote Windows PowerShell session to create a new registry key:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Use the &lt;b&gt;Get-Credential&lt;/b&gt; cmdlet to obtain a credential object with rights on the remote computer. Store the returned credential object in a variable.&lt;/li&gt;
&lt;li&gt;Use the &lt;b&gt;Enter-PSSession&lt;/b&gt; cmdlet to enter a remote Windows PowerShell session on the target computer.&lt;/li&gt;
&lt;li&gt;Use the &lt;b&gt;New-Item&lt;/b&gt; cmdlet to create the new registry key.&lt;/li&gt;
&lt;li&gt;Use the &lt;b&gt;Exit&lt;/b&gt; command to leave the remote Windows PowerShell session.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The commands to obtain credentials, enter a Windows PowerShell session, create a new registry key, and leave the Windows PowerShell session are shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$credential = Get-Credential -Credential iammred\administrator&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Enter-PSSession -ComputerName sql1 -Credential $credential&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;New-Item -Path HKCU:\Software -Name HSG -Value "my default value"&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Exit&lt;/p&gt;
&lt;p&gt;The use of these commands and the associated output are 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/3858.hsg_2D00_5_2D00_10_2D00_12_2D00_01.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3858.hsg_2D00_5_2D00_10_2D00_12_2D00_01.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I use Remote Desktop Protocol (RDP) to connect to the SQL1 server to verify creation of the registry key. Keep in mind that when you make a remote connection and create keys on the HKCU drive, the user account that makes the remote connection is the current user who will hold the newly created registry key. The newly created registry key 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/8547.hsg_2D00_5_2D00_10_2D00_12_2D00_02.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8547.hsg_2D00_5_2D00_10_2D00_12_2D00_02.png" alt="Image of Registry Editor" title="Image of Registry Editor" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Creating remote registry keys on multiple computers&lt;/h2&gt;
&lt;p&gt;Entering a remote Windows PowerShell session to create a registry key on multiple computers is a tedious and time-consuming process. To perform a command on multiple machines, it is better to use the &lt;b&gt;Invoke-Command&lt;/b&gt; cmdlet.&lt;/p&gt;
&lt;p&gt;Only the steps&amp;hellip;&lt;/p&gt;
&lt;p&gt;Using the &lt;b&gt;Invoke-Command&lt;/b&gt; cmdlet to create remote registry keys:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Store the server names in a variable.&lt;/li&gt;
&lt;li&gt;Store the connection credentials in a variable (use the &lt;b&gt;Get-Credential&lt;/b&gt; cmdlet to obtain the credentials).&lt;/li&gt;
&lt;li&gt;Use the &lt;b&gt;Invoke-Command&lt;/b&gt; cmdlet to run the command against the remote machines. Place the command to be run in the &lt;i&gt;ScriptBlock &lt;/i&gt;parameter.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The following commands create a new registry key on the HKCU drive on three different servers.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$servers = "hyperv1","hyperv2","hyperv3"&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;$credential = Get-Credential -Credential iammred\administrator&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Invoke-Command -ComputerName $servers -Credential $credential -ScriptBlock {New-Item -Path HKCU:\Software -Name hsg -Value "scripted default value"}&lt;/p&gt;
&lt;p&gt;The commands and the output associated with running the commands are 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/6378.hsg_2D00_5_2D00_10_2D00_12_2D00_03.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/6378.hsg_2D00_5_2D00_10_2D00_12_2D00_03.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The returning output from the &lt;b&gt;Invoke-Command&lt;/b&gt; cmdlet displays the computer name and illustrates the newly created registry key. However, if you wish further confirmation that the registry keys created properly, it is easy to change the &lt;b&gt;New-Item&lt;/b&gt; command to &lt;b&gt;Test-Path&lt;/b&gt;. Because the server names reside in a variable, in addition to the credentials, using &lt;b&gt;Test-Path&lt;/b&gt; inside the script block of the &lt;b&gt;Invoke-Command&lt;/b&gt; cmdlet is trivial. Here is the revised command.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Invoke-Command -ComputerName $servers -Credential $credential -ScriptBlock {Test-Path -Path HKCU:\Software\hsg}&lt;/p&gt;
&lt;p&gt;The command and its associated output are 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/2086.hsg_2D00_5_2D00_10_2D00_12_2D00_04.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/2086.hsg_2D00_5_2D00_10_2D00_12_2D00_04.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Creating property values&lt;/h2&gt;
&lt;p&gt;It is unusual to have a registry key that has only a default property value. In fact, most registry keys contain multiple property values. To create a new property value, use the &lt;b&gt;New-ItemProperty&lt;/b&gt; cmdlet. The following command creates a new property value named NewProperty under the previously created HSG registry key.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;New-ItemProperty -Path HKCU:\Software\hsg -Name NewProperty -Value "New PropertyValue"&lt;/p&gt;
&lt;p&gt;The newly created registry key property 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/1401.hsg_2D00_5_2D00_10_2D00_12_2D00_05.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/1401.hsg_2D00_5_2D00_10_2D00_12_2D00_05.png" alt="Image of Registry Editor" title="Image of Registry Editor" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Getting registry property values&lt;/h2&gt;
&lt;p&gt;When run, the command returns information about the registry key property. In fact, this is the same information that is obtained by using the &lt;b&gt;Get-ItemProperty&lt;/b&gt; cmdlet. The use of the &lt;b&gt;Get-ItemProperty&lt;/b&gt; cmdlet and the associated output from the command are shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; Get-ItemProperty -path HKCU:\Software\hsg -Name newproperty&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PSPath&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\hsg&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PSChildName&amp;nbsp; : hsg&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PSDrive&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : HKCU&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PSProvider&amp;nbsp;&amp;nbsp; : Microsoft.PowerShell.Core\Registry&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;NewProperty&amp;nbsp; : New PropertyValue&lt;/p&gt;
&lt;p&gt;The newly created registry property appears in the output under the name of the property. This means that to display only the value of the registry property requires essentially naming the property twice. The first time the registry property appears, it is the name of the registry property to obtain; the second time, it is the property to retrieve. This command and the associated output are shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;PS C:\&amp;gt; (Get-ItemProperty -path HKCU:\Software\hsg -Name newproperty).newProperty&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;New PropertyValue&lt;/p&gt;
&lt;p&gt;YH, that is all there is to using Windows PowerShell to create registry keys on remote systems. Registry Week will continue tomorrow when I will talk about enumerating registry key properties.&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;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&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=3496993" 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/registry/">registry</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/operating+system+/">operating system </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/getting+started/">getting started</category></item><item><title>Use PowerShell to Easily Create New Registry Keys</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/09/use-powershell-to-easily-create-new-registry-keys.aspx</link><pubDate>Wed, 09 May 2012 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3496802</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3496802</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/09/use-powershell-to-easily-create-new-registry-keys.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Microsoft Scripting Guy, Ed Wilson, shows how to use Windows PowerShell to create new registry keys on local and remote computers.&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! I am often required to create new registry keys on our computers. One of the reasons for this is for occasional system configuration. You see, in our company the Group Policy team is the Group Policy team. They do Group Policy&amp;mdash;but only for their own ends. They never make changes at the request of desktop support. In fact, they are reluctant to make any changes what-so-ever. Of course, when you are in charge of Group Policy for a multiforest, multidomain, international company with a presence on four continents, involving over a hundred-thousand machines, it is easy to understand their reluctance. Additionally, in the past, a few misguided Group Policy Objects (GPOs) were applied, and they brought the network to its knees. Anyway, long story short, I need an easy way to create new registry keys on our desktop machines.&lt;/p&gt;
&lt;p&gt;&amp;mdash;LL&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 LL,&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. This morning is a &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2009/09/08/hey-scripting-guy-september-8-2009.aspx" target="_blank"&gt;coffee morning&lt;/a&gt; for me. I was up late last night finishing a mystery novel, so when the alarm went off, it seemed like it was still &amp;ldquo;oh dark thirty,&amp;rdquo; so I thought I would make a pot of &lt;a href="http://en.wikipedia.org/wiki/Kona_coffee" target="_blank"&gt;Kona coffee&lt;/a&gt; in my &lt;a href="http://en.wikipedia.org/wiki/French_press" target="_blank"&gt;French press&lt;/a&gt; while the &lt;a href="http://technet.microsoft.com/en-us/scriptcenter/dd901334" target="_blank"&gt;Scripting Wife&lt;/a&gt; was busying herself making a couple of omelets. I am in my office listening to a new jazz/blues fusion CD that the mail person brought to our house yesterday. I was on the treadmill at the time, and this is the first chance I have had to give it a spin.&lt;/p&gt;
&lt;p&gt;I spent my time at the breakfast table (while waiting for the French Roast estate reserve beans to steep) reviewing my schedule. Here it is: the Scripting Wife and I are home for a few weeks, then we will be on the road for a couple of weeks. We are heading south, which when you already live in the deep south, generally means Florida. On June 1, 2012, we will be at the &lt;a href="http://www.atltechstravaganza.com/" target="_blank"&gt;Atlanta TechStravaganza&lt;/a&gt;. I will be making a couple of presentations, and if it is anything like it was last year, the day should be a ton of fun with tremendous learning and networking opportunities. Check out &lt;a href="http://technet.microsoft.com/en-us/scriptcenter/hh182567" target="_blank"&gt;the community page&lt;/a&gt; for more information about where I will be in the next month or so.&lt;/p&gt;
&lt;p&gt;LL, your story is, unfortunately, not uncommon. I was talking to several IT Pros at the Mark Minasi conference in Virginia Beach last week, and they echoed your sentiments&amp;mdash;Group Policy seems to be a rather large hammer with which to insert glazier points. Luckily, many of the tasks that are done via Group Policy are configurable through the registry. In fact, there are &lt;a href="http://www.microsoft.com/en-us/download/details.aspx?id=25250" target="_blank"&gt;Group Policy spreadsheets&lt;/a&gt; that document these settings, and they are available on the Microsoft Download Center.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Note&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;This is the third blog in a series of Hey, Scripting Guy! Blogs that discuss using the Registry provider. The first blog, &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/07/use-the-powershell-registry-provider-to-simplify-registry-access.aspx" target="_blank"&gt;Use the PowerShell Registry Provider to Simplify Registry Access&lt;/a&gt;&lt;i&gt;,&amp;nbsp;&lt;/i&gt;posted on Monday. Tuesday I discussed &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/08/use-powershell-to-back-up-system-state-prior-to-making-changes.aspx" target="_blank"&gt;using the *restore* cmdlets&lt;/a&gt; to perform a system state backup of a computer prior to manipulating the registry. For additional information about working with the registry via Windows PowerShell, &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/tags/windows+powershell/operating+system+/registry/" target="_blank"&gt;see this collection of blogs&lt;/a&gt;.&lt;/p&gt;
&lt;h1&gt;Creating new registry keys&lt;/h1&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Note&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; The registry contains information that is vital to the operation and configuration of your computer. Serious problems could arise if you edit the registry incorrectly. Therefore, it is important to back up your system prior to attempting to make any changes. For information about backing up your registry, see &lt;a href="http://support.microsoft.com/kb/322756" target="_blank"&gt;article 322756&lt;/a&gt; in the Microsoft Knowledge Base. For general information about working with the registry, see &lt;a href="http://support.microsoft.com/kb/310516" target="_blank"&gt;article 310516&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Creating a new registry key by using Windows PowerShell is the same as creating a new file or a new folder. All three processes use the &lt;b&gt;New-Item&lt;/b&gt; cmdlet. In addition, you might use the &lt;b&gt;Test-Path&lt;/b&gt; cmdlet to determine if the registry key already exists. You may also wish to change your working location to one of the registry drives. If you do this, you might use the &lt;b&gt;Push-Location&lt;/b&gt;, &lt;b&gt;Set-Location&lt;/b&gt;, and &lt;b&gt;Pop-Location&lt;/b&gt; cmdlets. This, of course, is the long way of doing things...&lt;/p&gt;
&lt;p&gt;Only the steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Store the current working location by using the &lt;b&gt;Push-Location&lt;/b&gt; cmdlet.&lt;/li&gt;
&lt;li&gt;Change the current working location to the appropriate registry drive by using the &lt;b&gt;Set-Location&lt;/b&gt; cmdlet.&lt;/li&gt;
&lt;li&gt;Use the &lt;b&gt;Test-Path&lt;/b&gt; cmdlet to determine if the registry key already exists.&lt;/li&gt;
&lt;li&gt;Use the &lt;b&gt;New-Item&lt;/b&gt; cmdlet to create the new registry key.&lt;/li&gt;
&lt;li&gt;Use the &lt;b&gt;Pop-Location&lt;/b&gt; cmdlet to return to the starting working location.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The following example creates a new registry key named &lt;b&gt;hsg&lt;/b&gt; off the HKEY_CURRENT_USERS software registry hive. It illustrates each of the previous five steps.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Push-Location&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Set-Location HKCU:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Test-Path .\Software\hsg&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;New-Item -Path .\Software -Name hsg&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Pop-Location&lt;/p&gt;
&lt;p&gt;The commands and the associated output from the commands are 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/4274.hsg_2D00_5_2D00_9_2D00_12_2D00_01.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/4274.hsg_2D00_5_2D00_9_2D00_12_2D00_01.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The newly created registry key is shown here in the Registry Editor tool.&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/4571.hsg_2D00_5_2D00_9_2D00_12_2D00_02.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/4571.hsg_2D00_5_2D00_9_2D00_12_2D00_02.png" alt="Image of Registry Editor page" title="Image of Registry Editor page" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;The short way to create a new registry key&lt;/h2&gt;
&lt;p&gt;It is not always necessary to change the working location to a registry drive when you create a new registry key. In fact, it is not even necessary to use the &lt;b&gt;Test-Path&lt;/b&gt; cmdlet to determine if the registry key exists. If the registry key already exists, an error generates. If you want to overwrite the registry key, use the &lt;i&gt;Force &lt;/i&gt;parameter.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;b&gt;Note&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;How you choose to deal with an already existing registry key is one of those &lt;i&gt;design decisions &lt;/i&gt;that confront IT Pros who venture far into the world of scripting. Software developers are very familiar with these types of decisions, and they usually deal with them in the analyzing requirements portion of the development life cycle. IT Pros who open the Windows PowerShell ISE first, and think about the design requirements second, become easily stymied, or else write-in problems. For more information about this, see my Microsoft Press book, &lt;a href="http://www.amazon.com/Windows-PowerShell-2-0-Best-Practices/dp/0735626464/ref=sr_1_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1255959455&amp;amp;sr=8-1"&gt;Windows PowerShell 2.0 Best Practices&lt;/a&gt;&lt;i&gt;. &lt;/i&gt;&lt;/p&gt;
&lt;p&gt;The following example creates a new registry key named &lt;b&gt;hsg&lt;/b&gt; in the HKCU:\Software location. Because the command includes the full path, it does not need to execute from the HKCU drive. Because the command uses the &lt;i&gt;Force &lt;/i&gt;switched parameter, the command overwrites the HKCU:\Software\HSG registry key if it already exists.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;New-Item -Path HKCU:\Software -Name hsg &amp;ndash;Force&lt;/p&gt;
&lt;p&gt;Only the steps&amp;hellip;&lt;/p&gt;
&lt;p&gt;The shortcut way to create a new registry key:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Include the full path to the registry key to create.&lt;/li&gt;
&lt;li&gt;Use the &lt;i&gt;Force &lt;/i&gt;parameter to overwrite any existing registry key of the same name.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;In the image that follows, the first attempt to create an hsg registry key fails because it already exists. The second command uses the &lt;i&gt;Force &lt;/i&gt;parameter, which causes the command to overwrite the existing registry key. Therefore, it succeeds without creating an error.&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/0207.hsg_2D00_5_2D00_9_2D00_12_2D00_03.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/0207.hsg_2D00_5_2D00_9_2D00_12_2D00_03.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Setting the default value for the key&lt;/h2&gt;
&lt;p&gt;The previous examples do not set the default value for the newly created registry key. If the registry key already exists (as it does in this specific case), use the &lt;b&gt;Set-Item&lt;/b&gt; cmdlet to assign a default value to the registry key as follows.&lt;/p&gt;
&lt;p&gt;Only the steps&amp;hellip;&lt;/p&gt;
&lt;p&gt;Assigning a default value to an existing registry key:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Use the &lt;b&gt;Set-Item&lt;/b&gt; cmdlet and supply the complete path to the existing registry key.&lt;/li&gt;
&lt;li&gt;Supply the default value in the &lt;i&gt;Value &lt;/i&gt;parameter of the &lt;b&gt;Set-Item&lt;/b&gt; cmdlet.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The following command assigns the value &lt;b&gt;&amp;ldquo;hsg key&amp;rdquo;&lt;/b&gt; to the default property value of the &lt;b&gt;hsg&lt;/b&gt; registry key that is contained in the HKCU:\Software location.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Set-Item -Path HKCU:\Software\hsg -Value "hsg key"&lt;/p&gt;
&lt;p&gt;The command does not return any information to the Windows PowerShell console when it runs. The modified registry key is shown here in the Registry Editor tool.&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/1715.hsg_2D00_5_2D00_9_2D00_12_2D00_04.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/1715.hsg_2D00_5_2D00_9_2D00_12_2D00_04.png" alt="Image of Registry Editor page" title="Image of Registry Editor page" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Use New-Item to create and assign a value&lt;/h2&gt;
&lt;p&gt;It is not necessary to use the &lt;b&gt;New-Item&lt;/b&gt; cmdlet to create a registry key and then to use the &lt;b&gt;Set-Item&lt;/b&gt; cmdlet to assign a default value. These steps are combinable to a single command. The following command creates a new registry key with the name &lt;b&gt;hsg1&lt;/b&gt;, and it assigns a default value of &lt;b&gt;&amp;ldquo;default value&amp;rdquo;&lt;/b&gt; to the registry key.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;New-Item -Path HKCU:\Software\hsg1 -Value "default value"&lt;/p&gt;
&lt;p&gt;The newly created registry key with default value 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/1651.hsg_2D00_5_2D00_9_2D00_12_2D00_05.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/1651.hsg_2D00_5_2D00_9_2D00_12_2D00_05.png" alt="Image of Registry Editor page" title="Image of Registry Editor page" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;LL, that is all there is to creating a new registry key. Registry Week will continue tomorrow when I will talk about modifying registry keys by using Windows PowerShell.&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;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3496802" 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/registry/">registry</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/operating+system+/">operating system </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/getting+started/">getting started</category></item><item><title>Use PowerShell to Back Up System State Prior to Making Changes</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/08/use-powershell-to-back-up-system-state-prior-to-making-changes.aspx</link><pubDate>Tue, 08 May 2012 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3496548</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3496548</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/08/use-powershell-to-back-up-system-state-prior-to-making-changes.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Learn how to use Windows PowerShell to back up system state prior to making changes to the registry.&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! I am interested in using Windows PowerShell to work with the registry, but everything I see talks about backing up the registry first. Is it possible to use Windows PowerShell to back up the registry?&lt;/p&gt;
&lt;p&gt;&amp;mdash;CG&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 CG,&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. Things are really becoming exciting around here. I have been in contact with &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/01/winners-of-the-2012-powershell-scripting-games-announced.aspx" target="_blank"&gt;the two winners from the 2012 Scripting Games&lt;/a&gt;, Rohn Edwards and Lido Paglia, and they are both coming to &lt;a href="http://northamerica.msteched.com/?mtag=scriptingguys#fbid=a7P5-eOcwVC" target="_blank"&gt;Microsoft TechEd 2012&lt;/a&gt;. I will later announce a time when they will be at the Scripting Guys booth, so if you are in Orlando at TechEd 2012, make sure that you can stop by. In addition, I have been talking to my good friend, Blaine Barton, who does the IT Time TechNet Radio podcast, and we will be doing a live broadcast from the TechEd floor as we talk to Rohn and Lido. This is not all&amp;mdash; I will make sure to announce any other cool things we come up with.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Note&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;This is the second blog in a series of Hey, Scripting Guy! Blogs that discuss using the Registry provider. The first blog, &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/07/use-the-powershell-registry-provider-to-simplify-registry-access.aspx" target="_blank"&gt;Using the Registry Provider to Simply Registry Access&lt;/a&gt; published on Monday. For additional information about working with the registry via Windows PowerShell, &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/tags/windows+powershell/operating+system+/registry/" target="_blank"&gt;see this collection of blogs&lt;/a&gt;.&lt;/p&gt;
&lt;h1&gt;Understanding the Computer Restore cmdlets&lt;/h1&gt;
&lt;p&gt;One of the easiest ways to ensure system reliability is to create a restore point prior to making potentially damaging changes. In this way, if a problem arises, it is rather simple to roll back the changes. In Windows PowerShell, the easy way to create a restore point is to use the Windows PowerShell cmdlets. These cmdlets require administrator rights (due to access to protected registry keys and other vital configuration files). Therefore, you need to right-click the Windows PowerShell icon and select &lt;b&gt;Run As Administrator&lt;/b&gt;&lt;i&gt; &lt;/i&gt;from the Action menu. Keep in mind that these cmdlets only work on client systems later than Windows&amp;nbsp;XP. These cmdlets do not work on server versions of the operating system. There are several cmdlets that you can use to work with system restore. These cmdlets and their associated descriptions are listed here.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;table border="1" cellspacing="0" cellpadding="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td width="319" valign="top"&gt;
&lt;p&gt;&lt;b&gt;Name&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="319" valign="top"&gt;
&lt;p&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Synopsis&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="319" valign="top"&gt;
&lt;p&gt;Enable-ComputerRestore&lt;/p&gt;
&lt;/td&gt;
&lt;td width="319" valign="top"&gt;
&lt;p&gt;Enables the System Restore feature on the specified file system drive.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="319" valign="top"&gt;
&lt;p&gt;Disable-ComputerRestore&lt;/p&gt;
&lt;/td&gt;
&lt;td width="319" valign="top"&gt;
&lt;p&gt;Disables the System Restore feature on the specified file system drive.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="319" valign="top"&gt;
&lt;p&gt;Get-ComputerRestorePoint&lt;/p&gt;
&lt;/td&gt;
&lt;td width="319" valign="top"&gt;
&lt;p&gt;Gets the restore points on the local computer.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="319" valign="top"&gt;
&lt;p&gt;Restore-Computer&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="319" valign="top"&gt;
&lt;p&gt;Starts a system restore on the local computer.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="319" valign="top"&gt;
&lt;p&gt;Checkpoint-Computer&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="319" valign="top"&gt;
&lt;p&gt;Creates a system restore point on the local computer.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Note&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;The following command retrieved the information in the previous table:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;"*restore*","checkpoint*" | % {get-help $_ }| select name, synopsis | ft -AutoSize &amp;ndash;Wrap&lt;/p&gt;
&lt;p&gt;The good thing is that the *restore* cmdlets use a standard WMI class: the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa378951(v=vs.85).aspx" target="_blank"&gt;SystemRestore WMI class&lt;/a&gt;. This class has documentation on MSDN, so MSDN is a great place to find additional information about the Windows PowerShell cmdlets.&lt;/p&gt;
&lt;h2&gt;Use CheckPoint-Computer to create a restore point&lt;/h2&gt;
&lt;p&gt;To create a new restore point, you use the &lt;b&gt;CheckPoint-Computer&lt;/b&gt; cmdlet. If the name of this cmdlet bothers you, you can create an alias to &lt;b&gt;New-ComputerRestorePoint&lt;/b&gt; by using the &lt;b&gt;New-Alias&lt;/b&gt; cmdlet as shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;new-alias -Name New-ComputerRestorePoint -Value Checkpoint-Computer&lt;/p&gt;
&lt;p&gt;When creating a new restore point via the &lt;b&gt;CheckPoint-Computer&lt;/b&gt; cmdlet, you can specify one of five values for the &lt;i&gt;RestorePointType &lt;/i&gt;parameter. The values are shown here.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;table border="1" cellspacing="0" cellpadding="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td width="213" valign="top"&gt;
&lt;p&gt;&lt;b&gt;Name&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="64" valign="top"&gt;
&lt;p&gt;&lt;b&gt;Value&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="361" valign="top"&gt;
&lt;p&gt;&lt;b&gt;Meaning&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="213" valign="top"&gt;
&lt;p&gt;APPLICATION_INSTALL&lt;/p&gt;
&lt;/td&gt;
&lt;td width="64" valign="top"&gt;
&lt;p&gt;0&lt;/p&gt;
&lt;/td&gt;
&lt;td width="361" valign="top"&gt;
&lt;p&gt;An application has been installed.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="213" valign="top"&gt;
&lt;p&gt;APPLICATION_UNINSTALL&lt;/p&gt;
&lt;/td&gt;
&lt;td width="64" valign="top"&gt;
&lt;p&gt;1&lt;/p&gt;
&lt;/td&gt;
&lt;td width="361" valign="top"&gt;
&lt;p&gt;An application has been uninstalled.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="213" valign="top"&gt;
&lt;p&gt;CANCELLED_OPERATION&lt;/p&gt;
&lt;/td&gt;
&lt;td width="64" valign="top"&gt;
&lt;p&gt;13&lt;/p&gt;
&lt;/td&gt;
&lt;td width="361" valign="top"&gt;
&lt;p&gt;An application needs to delete the restore point it created. For example, an application would use this flag when a user cancels an installation.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="213" valign="top"&gt;
&lt;p&gt;DEVICE_DRIVER_INSTALL&lt;/p&gt;
&lt;/td&gt;
&lt;td width="64" valign="top"&gt;
&lt;p&gt;10&lt;/p&gt;
&lt;/td&gt;
&lt;td width="361" valign="top"&gt;
&lt;p&gt;A device driver has been installed.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="213" valign="top"&gt;
&lt;p&gt;MODIFY_SETTINGS&lt;/p&gt;
&lt;/td&gt;
&lt;td width="64" valign="top"&gt;
&lt;p&gt;12&lt;/p&gt;
&lt;/td&gt;
&lt;td width="361" valign="top"&gt;
&lt;p&gt;An application has had features added or removed.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The default value for the &lt;i&gt;RestorePointType &lt;/i&gt;parameter is APPLICATION_INSTALL. Therefore, leaving the &lt;i&gt;RestorePointType &lt;/i&gt;parameter out of the command causes the cmdlet to create this type of restore point.&lt;/p&gt;
&lt;p&gt;Because you are getting ready to modify the registry, you can use the default &lt;i&gt;RestorePointType &lt;/i&gt;value. This command is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Checkpoint-Computer -Description "prior to adding registry key"&lt;/p&gt;
&lt;p&gt;You can use the &lt;b&gt;Get-ComputerRestorePoint&lt;/b&gt; cmdlet to obtain a list of the most recent computer restore points. This command is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; Get-ComputerRestorePoint&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Warning&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Column "RestorePointType" does not fit into the display and it was removed.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;CreationTime&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Description&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SequenceNumber&amp;nbsp;&amp;nbsp;&amp;nbsp; EventType&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;&amp;nbsp; -----------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;4/17/2012 4:51:37 PM&amp;nbsp;&amp;nbsp; Windows Update&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 38&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BEGIN_SYS...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;4/19/2012 3:53:55 PM&amp;nbsp;&amp;nbsp; Windows Update&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 39&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BEGIN_SYS...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;4/19/2012 3:57:07 PM&amp;nbsp;&amp;nbsp; Windows Live Essentials&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 40&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BEGIN_SYS...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;4/19/2012 3:57:19 PM&amp;nbsp;&amp;nbsp; Installed DirectX&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 41&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BEGIN_SYS...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;4/19/2012 3:57:24 PM&amp;nbsp;&amp;nbsp; Installed DirectX&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 42&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BEGIN_SYS...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;4/19/2012 3:57:48 PM&amp;nbsp;&amp;nbsp; WLSetup&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 43&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BEGIN_SYS...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;4/24/2012 9:11:12 AM&amp;nbsp;&amp;nbsp; Windows Update&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 44&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BEGIN_SYS...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;4/25/2012 1:48:52 PM&amp;nbsp;&amp;nbsp; Windows Update&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 45&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BEGIN_SYS...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;4/29/2012 9:43:11 AM&amp;nbsp;&amp;nbsp; Windows Update&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 46&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BEGIN_SYS...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;4/30/2012 11:27:01 AM&amp;nbsp; Installed Microsoft&amp;nbsp; File T... 47&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BEGIN_SYS...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;5/2/2012 10:51:17 AM&amp;nbsp;&amp;nbsp; Installed Intel(R) PROSet/W... 48&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BEGIN_SYS...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;5/2/2012 10:04:24 PM&amp;nbsp;&amp;nbsp; Windows Update&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 50&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BEGIN_SYS...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;5/4/2012 10:22:41 AM&amp;nbsp;&amp;nbsp; Windows Update&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 51&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BEGIN_SYS...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;5/7/2012 12:01:48 PM&amp;nbsp;&amp;nbsp; Windows Update&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 52&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BEGIN_SYS...&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;5/7/2012 2:02:12 PM&amp;nbsp;&amp;nbsp;&amp;nbsp; prior to adding registry key&amp;nbsp;&amp;nbsp; 53&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BEGIN_SYS...&lt;/p&gt;
&lt;h2&gt;Verifying the status of the last restore point&lt;/h2&gt;
&lt;p&gt;Unfortunately, this command provides no information about the success of the last attempt to create a restore point for the computer. Selecting the most recent checkpoint and sending the output to the &lt;b&gt;Format-List&lt;/b&gt; cmdlet with the &lt;i&gt;Force &lt;/i&gt;parameter, displays additional information, but it does not provide any information about the success or failure of the checkpoint. This command and associated output are shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; Get-ComputerRestorePoint -RestorePoint 53 | fl * -Force&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;__GENUS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;: 2&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;__CLASS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : SystemRestore&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;__SUPERCLASS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; :&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;__DYNASTY&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : SystemRestore&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;__RELPATH&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : SystemRestore.SequenceNumber=53&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;__PROPERTY_COUNT : 5&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;__DERIVATION&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : {}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;__SERVER&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : EDLT&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;__NAMESPACE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : root\default&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;__PATH&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;: \\EDLT\root\default:SystemRestore.SequenceNumber=53&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;CreationTime&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 20120507180212.613222-000&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Description&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : prior to adding registry key&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;EventType&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 100&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;RestorePointType : 0&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;SequenceNumber&amp;nbsp;&amp;nbsp; : 53&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Scope&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : System.Management.ManagementScope&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Path&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : \\EDLT\root\default:SystemRestore.SequenceNumber=53&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Options&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : System.Management.ObjectGetOptions&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;ClassPath&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : \\EDLT\root\default:SystemRestore&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Properties&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : {CreationTime, Description, EventType, RestorePointType...}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;SystemProperties : {__GENUS, __CLASS, __SUPERCLASS, __DYNASTY...}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Qualifiers&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : {dynamic}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Site&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;Container&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; :&lt;/p&gt;
&lt;p&gt;The &lt;b&gt;Get-ComputerRestorePoint&lt;/b&gt; cmdlet does have a &lt;i&gt;LastStatus &lt;/i&gt;switched parameter, which according to Help, &amp;ldquo;Gets the status of the most recent system restore operation.&amp;rdquo; Unfortunately, the parameter provides only cryptic information such as shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; Get-ComputerRestorePoint -LastStatus | fl *&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;The last attempt to restore the computer failed.&lt;/p&gt;
&lt;p&gt;Without any dates, operation IDs or other detailed information, the &lt;i&gt;LastStatus &lt;/i&gt;parameter cannot be relied on to make a decision in relation to the success or failure of the computer&amp;rsquo;s system restore point.&lt;/p&gt;
&lt;h2&gt;See the Event Log for restore point status&lt;/h2&gt;
&lt;p&gt;The best place to determine the success (or failure) of the attempt to create a restore point for the computer is the &lt;i&gt;Application &lt;/i&gt;Event Log. The pertinent event (event ID 8194) 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/7750.hsg_2D00_5_2D00_8_2D00_12_2D00_01.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/7750.hsg_2D00_5_2D00_8_2D00_12_2D00_01.png" alt="Image of event" title="Image of event" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Because you already have Windows PowerShell open, it is much faster to use the &lt;b&gt;Get-EventLog&lt;/b&gt; cmdlet to obtain this information than to open the Event Viewer utility, navigate to the Windows Logs, select the Application log, and find the 8194 events in the log viewer. The command to find the latest 8194 event from the application log is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Get-EventLog -LogName application -InstanceId 8194 -Newest 1 | fl *&lt;/p&gt;
&lt;p&gt;The command and the associated output are 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/1374.hsg_2D00_5_2D00_8_2D00_12_2D00_02.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/1374.hsg_2D00_5_2D00_8_2D00_12_2D00_02.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;CG, that is all there is to using the &lt;b&gt;CheckPoint-Computer&lt;/b&gt; cmdlet to create a system restore point and back up the registry. Registry Week will continue tomorrow when I will talk about creating new Registry keys and property values via the Windows PowerShell Registry provider.&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;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&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=3496548" 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/registry/">registry</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/operating+system+/">operating system </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/getting+started/">getting started</category></item><item><title>Use the PowerShell Registry Provider to Simplify Registry Access</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/07/use-the-powershell-registry-provider-to-simplify-registry-access.aspx</link><pubDate>Mon, 07 May 2012 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3496184</guid><dc:creator>The Scripting Guys</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.technet.com/b/heyscriptingguy/rsscomments.aspx?WeblogPostID=3496184</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/07/use-the-powershell-registry-provider-to-simplify-registry-access.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Microsoft Scripting Guy, Ed Wilson, shows how to use the Windows PowerShell registry provider to simplify access to registry keys and properties.&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! I know that I am not supposed to mess around with the Registry on my computer, but the simple fact is that many times there are Registry values that need to be changed. In addition, there are always lots of TechNet articles that talk about changing the registry. So here is my question: In the past I used WMI to modify Registry settings. It worked. In fact, it worked remotely, but it was pretty much a mess. Does Windows PowerShell make it easier to edit the registry?&lt;/p&gt;
&lt;p&gt;&amp;mdash;MG&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 MG,&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. This is a great time to be using Windows PowerShell. In Windows PowerShell&amp;nbsp;2.0, we got true remoting, which makes it easy to run a single command or a series of commands on one or more remote computers. In fact, you can open a Windows PowerShell console that targets a remote computer, and work as if you were logged on to the console. You may ask, &amp;ldquo;Why is Ed talking about remoting when I asked about the Registry?&amp;rdquo; Well, it is because of the way that you will work with the registry in Windows PowerShell. In Windows PowerShell&amp;nbsp;1.0, there was no remoting. This meant that if you wanted to edit the Registry on a remote computer, you might very well end up using the same WMI classes that you used in the VBScript days. (There were other ways, but for one coming from a VBScript background, using the WMI classes makes sense.)&lt;/p&gt;
&lt;h2&gt;Understanding the Registry provider&lt;/h2&gt;
&lt;p&gt;In Windows PowerShell&amp;nbsp;1.0, the Registry provider made it easy to work with the registry on the local system. Unfortunately, without remoting, you were limited to working with the local computer or using some other remoting mechanism (perhaps a logon script) to make changes on remote systems. With Windows PowerShell&amp;nbsp;2.0 the inclusion of remoting makes it possible to make remote registry changes as easily changing the local registry.&lt;/p&gt;
&lt;p&gt;The Registry provider permits access to the Registry in the same manner as the file system provider permits access to a local disk drive. The same cmdlets that are used to access the file system (for example, &lt;b&gt;New-Item&lt;/b&gt;, &lt;b&gt;Get-ChildItem&lt;/b&gt;, &lt;b&gt;Set-Item&lt;/b&gt;, and &lt;b&gt;Remove-Item&lt;/b&gt;) also work with the Registry.&lt;/p&gt;
&lt;h2&gt;The two registry drives&lt;/h2&gt;
&lt;p&gt;By default, the Registry provider creates two registry drives. To find all of the drives that are exposed by the Registry provider, use the &lt;b&gt;Get-PSDrive&lt;/b&gt; cmdlet. These drives are shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; Get-PSDrive -PSProvider registry | select name, root&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Root&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;HKCU&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HKEY_CURRENT_USER&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;HKLM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HKEY_LOCAL_MACHINE&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Additional registry drives are created by using the &lt;b&gt;New-PSDrive&lt;/b&gt; cmdlet. For example, it is common to create a registry drive for the HKEY_CLASSES_ROOT registry hive. The code to do this is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; New-PSDrive -PSProvider registry -Root HKEY_CLASSES_ROOT -Name HKCR&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;WARNING: column "CurrentLocation" does not fit into the display and was removed.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Used (GB)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Free (GB) Provider&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Root&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;&amp;nbsp; ---------&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;HKCR&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Registry&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HKEY_CLASSES_ROOT&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;When created, the new HKCR drive is accessible in the same way as any other drive. For example, to change the working location to the HKCR drive, use the &lt;b&gt;Set-Location&lt;/b&gt; cmdlet or one of its aliases (such as &lt;b&gt;cd&lt;/b&gt;). This technique is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS C:\&amp;gt; Set-Location HKCR:&lt;/p&gt;
&lt;p&gt;To determine the current location, use the &lt;b&gt;Get-Location&lt;/b&gt; cmdlet as shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS HKCR:\&amp;gt; Get-Location&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Path&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;----&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;HKCR:\&lt;/p&gt;
&lt;p&gt;When set, explore the new working location by using the &lt;b&gt;Get-ChildItem&lt;/b&gt; cmdlet (or one of the aliases for that cmdlet such as &lt;b&gt;dir&lt;/b&gt;). This technique 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/1754.hsg_2D00_5_2D00_7_2D00_12_2D00_01.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/1754.hsg_2D00_5_2D00_7_2D00_12_2D00_01.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Retrieving Registry values&lt;/h2&gt;
&lt;p&gt;To view the values that are stored in a registry key, use the &lt;b&gt;Get-Item&lt;/b&gt; or the &lt;b&gt;Get-ItemProperty&lt;/b&gt; cmdlet. Using the &lt;b&gt;Get-Item&lt;/b&gt; cmdlet reveals that there is one property (named &lt;b&gt;default&lt;/b&gt;). This is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS HKCR:\&amp;gt; Get-Item .\.ps1 | fl *&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PSPath&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Microsoft.PowerShell.Core\Registry::HKEY_CLASSES_ROOT\.ps1&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PSParentPath&amp;nbsp; : Microsoft.PowerShell.Core\Registry::HKEY_CLASSES_ROOT&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PSChildName&amp;nbsp;&amp;nbsp; : .ps1&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PSDrive&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : HKCR&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PSProvider&amp;nbsp;&amp;nbsp;&amp;nbsp; : Microsoft.PowerShell.Core\Registry&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PSIsContainer : True&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Property&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : {(default)}&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;SubKeyCount&amp;nbsp;&amp;nbsp; : 1&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;ValueCount&amp;nbsp;&amp;nbsp;&amp;nbsp; : 1&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : HKEY_CLASSES_ROOT\.ps1&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;To access the value of the &lt;b&gt;default&lt;/b&gt;&lt;i&gt; &lt;/i&gt;property requires using the &lt;b&gt;Get-ItemProperty&lt;/b&gt; cmdlet as shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS HKCR:\&amp;gt; Get-ItemProperty .\.ps1 | fl *&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PSPath&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Microsoft.PowerShell.Core\Registry::HKEY_CLASSES_ROOT\.ps1&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CLASSES_ROOT&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PSChildName&amp;nbsp; : .ps1&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PSDrive&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : HKCR&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PSProvider&amp;nbsp;&amp;nbsp; : Microsoft.PowerShell.Core\Registry&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;(default)&amp;nbsp;&amp;nbsp;&amp;nbsp; : Microsoft.PowerShellScript.1&lt;/p&gt;
&lt;p&gt;&amp;nbsp;The technique for accessing registry keys and the values associated with them 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/1423.hsg_2D00_5_2D00_7_2D00_12_2D00_02.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/1423.hsg_2D00_5_2D00_7_2D00_12_2D00_02.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;To return only the value of the &lt;b&gt;default&lt;/b&gt;&lt;i&gt; &lt;/i&gt;property requires a bit of manipulation. The &lt;b&gt;default&lt;/b&gt;&lt;i&gt; &lt;/i&gt;property requires using literal quotation marks to force the evaluation of the parentheses in the name. This is shown here.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS HKCR:\&amp;gt; (Get-ItemProperty .\.ps1 -Name '(default)').'(default)'&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Microsoft.PowerShellScript.1&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;PS HKCR:\&amp;gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;MG, that is all there is to using the Registry provider in Windows PowerShell. Registry Provider Week will continue tomorrow when I will talk about creating and modifying registry keys.&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;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&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=3496184" 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/registry/">registry</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/operating+system+/">operating system </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/getting+started/">getting started</category></item><item><title>Weekend Scripter: How to Print Documents from the TechNet Library and MSDN</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/06/create-and-print-documentation-from-the-technet-library-or-msdn.aspx</link><pubDate>Sun, 06 May 2012 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3494772</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=3494772</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/06/create-and-print-documentation-from-the-technet-library-or-msdn.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: With the &lt;b&gt;Build-a-Book &lt;/b&gt;feature in the TechNet Library and MSDN, you can combine topics into a package to download for offline reading or printing.&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. Today&amp;rsquo;s post is by Dave Bishop. He explains a cool new tool that enables readers to assemble and print documents directly from content in the Microsoft TechNet Library and MSDN.&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/8360.7178.SquareDave.jpg_2D00_100x0.jpg"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/150x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8360.7178.SquareDave.jpg_2D00_100x0.jpg" alt="Photo of Dave Bishop" title="Photo of Dave Bishop" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Dave is the manager of the Windows Server Manageability Documentation team at Microsoft, which includes the documentation for Windows PowerShell. He&amp;rsquo;s a former ITPro, and a long time scripter who has automated many of his daily tasks with Windows PowerShell.&lt;/p&gt;
&lt;p&gt;Take it away, Dave&amp;hellip;&lt;/p&gt;
&lt;p&gt;At Microsoft, we have been publishing documents to the web for a long time. The team that I lead (Windows Server Manageability Documentation) and my peer teams used to be in the business of writing chapters for books and producing a lot of Help files that were included &amp;ldquo;on-the-box&amp;rdquo; with the Windows and Windows Server operating systems. These days we produce very few of either for many reasons. The biggest reason is a shift to publishing our content on the web, which enables us to keep it up-to-date. Books and Help files had to be finished months before the products they described were released. This almost guaranteed that they were out-of-date as soon as they were published. When updates and Service Packs came along, that static content quickly became more inaccurate, and we frustratingly had (and still have) almost no opportunity to update that content.&lt;/p&gt;
&lt;p&gt;On the other hand, content that we publish to the Microsoft TechNet Library on the web can be updated quickly and regularly, enabling us to fix mistakes that slipped by, add more information where a gap was identified, and so on. We think that is a huge win for our customers and we&amp;rsquo;ve gone all-in to move our content to the web. Because of the ability to update our content, it also means that feedback from our customers is more important than ever before! Although we always were interested in feedback, we can now do more about it, so please continue to rate topics and provide your comments.&lt;/p&gt;
&lt;p&gt;All that said, the switch to web-based content was not without some perceived drawbacks. Some of you made the adjustment from paper books to the browser well, but others still prefer to capture some reading material in a form that can be reviewed offline. Until recently, that meant that we had to package our more popular documents as Word or PDF files and post them to the Microsoft Download Center where customers could download and print them. Although we certainly understand the need for that, it meant that we had two documents to maintain instead of only one, and we risked accidentally updating only one of them. Obviously, that&amp;rsquo;s not a good experience for anyone!&lt;/p&gt;
&lt;p&gt;Recently, the folks who maintain the infrastructure for TechNet and MSDN introduced a new feature that the writing teams are very happy to see. We call it &lt;b&gt;Build-a-Book&lt;/b&gt;, and it enables you to combine any topics that you like into a single package that you can download for offline reading or printing. Let me introduce you to this very cool feature&amp;hellip;&lt;/p&gt;
&lt;p&gt;Imagine the following scenario&amp;mdash;and you can follow along if you&amp;rsquo;d like; the feature is live today!&lt;/p&gt;
&lt;p&gt;You are a new convert to Windows PowerShell because of The Scripting Guy&amp;rsquo;s excellent blog and the recently completed Scripting Games. You want to learn more about this truly awesome technology, and your search brings you to the following &lt;a href="http://aka.ms/kdehpr" target="_blank"&gt;Windows PowerShell&lt;/a&gt; site in the TechNet Library: &lt;a href="http://aka.ms/kdehpr" target="_blank"&gt;http://aka.ms/kdehpr&lt;/a&gt;.&lt;/p&gt;
&lt;p&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/1108.pic1.jpg"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/1108.pic1.jpg" alt="Image of website" title="Image of website" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;After browsing a bit, you decide that you want to download the entire &lt;i&gt;Getting Started with Windows PowerShell&lt;/i&gt; document&amp;mdash;maybe even print it. In the &amp;ldquo;old days&amp;rdquo;, the only way to print from the TechNet Library was to navigate to each page one-by-one and then print from your browser, usually resulting in lots of wasted paper because so much of the Table of Contents and the page&amp;rsquo;s &amp;ldquo;chrome&amp;rdquo; was included in the printout. Yuck. Super tedious. So 20&lt;sup&gt;th&lt;/sup&gt; century.&lt;/p&gt;
&lt;p&gt;Instead, let&amp;rsquo;s try the new improved process. In the upper-right hand corner of the page, click the Print icon, and then on the menu that appears, click &lt;b&gt;Print Multiple Topics&lt;/b&gt;.&lt;/p&gt;
&lt;p&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/3755.Pic2.jpg"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/150x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3755.Pic2.jpg" alt="Image of icon" title="Image of icon" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;This takes you to a page that explains the downloading process and how to select topics to include. By all means, read it; &amp;nbsp;but I won&amp;rsquo;t bother repeating it here. Click the &lt;b&gt;Start&lt;/b&gt; button on the left side of the page near the top. You&amp;rsquo;ll find yourself right back at the TechNet Library page from which you began this little journey. But now your vehicle has a new dashboard accessory in the form of this little toolbar:&lt;/p&gt;
&lt;p&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/5141.Pic3.JPG"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/5141.Pic3.JPG" alt="Image of toolbar" title="Image of toolbar" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The presence of this toolbar shows that you have the &lt;b&gt;Build-A-Book&lt;/b&gt; feature turned on, and it&amp;rsquo;s ready for you to start assembling your package. Notice that you can easily add the topic you&amp;rsquo;re currently viewing&amp;mdash;simply click &lt;b&gt;Add this Topic&lt;/b&gt; adjacent to the green plus sign. But in our scenario, we want to add the entire &lt;i&gt;Getting Started with Windows PowerShell&lt;/i&gt; document. That&amp;rsquo;s easy too. &amp;nbsp;All you have to do is to right-click the title of the topic that is the parent of all the topics that you want to include, as shown here:&lt;/p&gt;
&lt;p&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/0602.Pic4.JPG"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/350x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/0602.Pic4.JPG" alt="Image of menu" title="Image of menu" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;To make sure, the system asks you if you want only the one topic or all the topics included in that branch of the tree&amp;mdash;in this case 45 topics. Click &lt;b&gt;Add This Set of Topics (45)&lt;/b&gt;, and you&amp;rsquo;ll see that the toolbar updates to show that your collection is 45 topics heavier.&lt;/p&gt;
&lt;p&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/4786.Pic5.JPG"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/4786.Pic5.JPG" alt="Image of toolbar" title="Image of toolbar" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;To make the rest of this example a bit more interesting, let&amp;rsquo;s also grab the &lt;i&gt;Windows PowerShell User&amp;rsquo;s Guide&lt;/i&gt;. Right-click that topic in the Table of Contents, and then click &lt;b&gt;Add This Set of Topics (43)&lt;/b&gt;. Now your collection has 88 topics.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s examine the collection. Simply click the &lt;b&gt;Collection&lt;/b&gt; link in the toolbar, and the following page appears:&lt;/p&gt;
&lt;p&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/4375.PIC6.JPG"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/4375.PIC6.JPG" alt="Image of webpage" title="Image of webpage" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You can see that your collection is named &lt;i&gt;My Collection&lt;/i&gt;; and currently, it contains a single chapter creatively named &amp;ldquo;Chapter 1&amp;rdquo;. That chapter contains the two sets of topics you selected. Before downloading it, let&amp;rsquo;s tidy things up a bit. First of all, click &lt;b&gt;Rename&lt;/b&gt; next to the &lt;i&gt;My Collection&lt;/i&gt; name, type a new name with a little more context and pizazz, and then click &lt;b&gt;Done&lt;/b&gt;. In my example, I used &lt;i&gt;Starting the PowerShell Journey&lt;/i&gt;. Isn&amp;rsquo;t that so much catchier than &lt;i&gt;My Collection&lt;/i&gt;?&lt;/p&gt;
&lt;p&gt;Next, let&amp;rsquo;s turn each document into it&amp;rsquo;s own chapter. Click &lt;b&gt;Add Chapter&lt;/b&gt; in the upper-right:&lt;/p&gt;
&lt;p&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/1805.Pic7.JPG"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/250x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/1805.Pic7.JPG" alt="Image of menu" title="Image of menu" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Give your chapter a new name by typing &amp;ldquo;User&amp;rsquo;s Guide&amp;rdquo;, and then click &lt;b&gt;OK&lt;/b&gt;.&lt;/p&gt;
&lt;p&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/7103.Pic8.JPG"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/300x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/7103.Pic8.JPG" alt="Image of menu" title="Image of menu" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Now you can drag the &lt;i&gt;Windows PowerShell User&amp;rsquo;s Guide&lt;/i&gt; document down to your new chapter. Left-click &amp;nbsp;the four-arrow icon that is located on the left of the document, then drag it from its starting location to where you want it. In this case, drag it to directly under the &lt;i&gt;User&amp;rsquo;s Guide &lt;/i&gt;title.&lt;/p&gt;
&lt;p&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/3223.Pic9.JPG"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/400x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3223.Pic9.JPG" alt="Image of menu" title="Image of menu" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;All that&amp;rsquo;s left to do is to rename the original Chapter 1. Click &lt;b&gt;Rename&lt;/b&gt; there, and type &amp;ldquo;Getting Started Guide&amp;rdquo;. When you&amp;rsquo;re done, it should look like this:&lt;/p&gt;
&lt;p&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/1067.Pic10.JPG"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/400x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/1067.Pic10.JPG" alt="Image of menu" title="Image of menu" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Before we actually download the collection, let&amp;rsquo;s check a few other options. Click &lt;b&gt;Advanced Options&lt;/b&gt; to see the (ahem) advanced options.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Example Code Language&lt;/b&gt; lets you filter to include only the examples that use the language(s) that you are interested in. When an MSDN topic supports many different programming language examples, this option can be very useful. (We&amp;rsquo;re working to get Windows PowerShell added to this list!)&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Include Community Content&lt;/b&gt; lets you choose whether to include content that was written by people outside of Microsoft. Sometimes there is some truly excellent stuff out there, so be sure to review it before making a decision here.&lt;/li&gt;
&lt;li&gt;The final option enables you to specify how to handle translated content. Do you want to include the original (likely English), the translated version, or both?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Finally, you can specify how you want to download your newly customized book of knowledge. For this example, select &lt;b&gt;PDF&lt;/b&gt; from the drop-down list, and then click &lt;b&gt;Generate&lt;/b&gt;. If you are not yet logged in, you&amp;rsquo;ll be asked to do so before you can download your completed file. Give it a few minutes. Depending on how many topics you included, the server takes a bit of time to process and add them to the downloaded file. As long as the &lt;b&gt;Current Topic:&lt;/b&gt; title changes every few seconds, it&amp;rsquo;s on track.&lt;/p&gt;
&lt;p&gt;When it displays the following page, right-click &lt;b&gt;Download Your Document&lt;/b&gt;, click &lt;b&gt;Save target as&amp;hellip;&lt;/b&gt;, and then specify the file name and folder where you want to save your finished document.&lt;/p&gt;
&lt;p&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/0602.pic11.JPG"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/500x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/0602.pic11.JPG" alt="Image of menu" title="Image of menu" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;After it&amp;rsquo;s saved locally, you can use your favorite PDF reader program to view it, transfer it to your favorite eReader device (most of them support PDF files), or print it for that truly classic &amp;ldquo;paper&amp;rdquo; feel. Your collections will persist for the session, so you can go back to add additional topics, remove topics that you don&amp;rsquo;t want, or totally rearrange the whole document. It&amp;rsquo;s completely up to you! &amp;nbsp;&lt;/p&gt;
&lt;p&gt;I hope you think this new feature in the TechNet Library and MSDN is as cool as I do. It simplifies our publishing to one location and gives you additional flexibility to download and print topics or collections of topics that are useful to you.&lt;/p&gt;
&lt;p&gt;Please let us know what we can do to improve your documenation experience. You can email me and my team at &lt;a href="mailto:mgmtdocfb@microsoft.com?subject=Feedback%20on%20Windows%20Server%20Manageability%20Docs&amp;amp;body=I'd%20like%20to%20provide%20feedback%20on%20the%20following%20documentation" target="_blank"&gt;mgmtdocfb@microsoft.com&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;~Dave&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;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&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=3494772" 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/Weekend+Scripter/">Weekend Scripter</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/Dave+Bishop/">Dave Bishop</category></item><item><title>Weekend Scripter: Active Directory Account Unlock Shortcut for Help Desk</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/05/weekend-scripter-active-directory-account-unlock-shortcut-for-help-desk.aspx</link><pubDate>Sat, 05 May 2012 07:01:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3494770</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=3494770</wfw:commentRss><comments>http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/05/weekend-scripter-active-directory-account-unlock-shortcut-for-help-desk.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Today&amp;rsquo;s post is a quick Windows PowerShell tip to save time for the Help Desk to unlock Active Directory accounts.&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. I was talking to Ashley the other day, and he was telling me about a cool tip he came up with that many of his customers had been using on a regular basis. Although the technique is rather basic, he said that the customers found it to be extremely valuable. I told him, &amp;ldquo;Well, why don&amp;rsquo;t you write up a quick post, and we will put it on the Hey, Scripting Guy! Blog.&amp;rdquo; Today&amp;rsquo;s post is a result of that conversation.&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/8203.wes_2D00_5_2D00_5_2D00_12_2D00_1.jpg"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/150x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8203.wes_2D00_5_2D00_5_2D00_12_2D00_1.jpg" border="0" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Ashley McGlone is a premier field engineer (PFE) for Microsoft. He started writing code on a Commodore VIC20 in 1982, and he has been hooked ever since. Today he specializes in Active Directory and Windows PowerShell, helping Microsoft Premier Customers reach their full potential through risk assessments and workshops. Ashley&amp;rsquo;s favorite workshop to teach is Windows PowerShell Essentials, and his TechNet blog focuses on real-world solutions for Active Directory by using Windows PowerShell.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;Blog: &lt;a href="http://blogs.technet.com/b/ashleymcglone"&gt;http://blogs.technet.com/b/ashleymcglone&lt;/a&gt;&lt;br /&gt; Twitter: @GoateePFE&lt;/p&gt;
&lt;p&gt;I was teaching a Windows PowerShell class last week, and my favorite part is always the last afternoon when I help students start their own scripts. One student asked if there is a way to put a shortcut on the desktop for the Help Desk staff to unlock Active Directory accounts. I said, "Sure! This sounds like fun." In only a couple minutes, we crafted this quick batch command that launches Windows PowerShell, loads the Active Directory module, prompts for the account name, and then unlocks it. Essentially, it is one wrapped line of code (not counting the "echo off"), as shown here:&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;@echo off &lt;br /&gt; powershell.exe -Command "&amp;amp; {Import-Module ActiveDirectory; Read-Host "Enter the user account to unlock" | Unlock-ADAccount}"&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/6355.wes_2D00_5_2D00_5_2D00_12_2D00_2.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/6355.wes_2D00_5_2D00_5_2D00_12_2D00_2.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Then another student asked if we could prompt for credentials in case they needed to use a different account to perform the unlock. That was a quick edit to add the &lt;i&gt;-Credential&lt;/i&gt; parameter with a prompt for &lt;b&gt;creds&lt;/b&gt;.&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;@echo off &lt;br /&gt; powershell.exe -Command "&amp;amp; {Import-Module ActiveDirectory; Read-Host "Enter the user account to unlock" | Unlock-ADAccount -Credential $(Get-Credential)}"&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/5074.wes_2D00_5_2D00_5_2D00_12_2D00_3.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/5074.wes_2D00_5_2D00_5_2D00_12_2D00_3.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Follow these steps to create your quick unlock shortcut:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create an empty BAT file on your desktop.&lt;/li&gt;
&lt;li&gt;Paste the previous script.&lt;/li&gt;
&lt;li&gt;Save.&lt;/li&gt;
&lt;li&gt;Double-click.&lt;/li&gt;
&lt;li&gt;That's it!&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Note&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;This requires a workstation running Windows&amp;nbsp;7 with the &lt;a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;amp;id=7887" target="_blank" title="RSAT"&gt;RSAT&lt;/a&gt; installed and the Active Directory cmdlet feature enabled. Also, you must be running Active Directory Web Services on at least one domain controller. You can find instructions for RSAT and Active Directory Web Services in my blog &lt;a href="http://blogs.technet.com/b/ashleymcglone/archive/2011/03/17/step-by-step-how-to-use-active-directory-powershell-cmdlets-against-2003-domain-controllers.aspx" target="_blank"&gt;Step-by-Step: How to use Active Directory PowerShell cmdlets against 2003 domain controllers&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The beauty of this shortcut involves calling Windows PowerShell.exe and passing in the script block. In the script block, notice that we use the semicolon for new lines, which enables us to wrap multiple lines into a single line.&lt;/p&gt;
&lt;p&gt;I hope this saves you time with the Help Desk. If you would like some other time-saving tips for using Windows PowerShell for the Help Desk, see my blog &lt;a href="http://blogs.technet.com/b/ashleymcglone/archive/2012/04/18/how-to-close-helpdesk-tickets-faster-with-powershell.aspx" target="_blank"&gt;How to close helpdesk tickets faster with PowerShell&lt;/a&gt;. P.S. If you would like to book a Windows PowerShell Essentials workshop with a Microsoft PFE, contact your premier technical account manager (TAM) for more information.&lt;/p&gt;
&lt;p&gt;Enjoy!&lt;br /&gt; ~Ashley&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;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&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=3494770" 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/Active+Directory/">Active Directory</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/user+accounts/">user accounts</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/guest+blogger/">guest blogger</category><category domain="http://blogs.technet.com/b/heyscriptingguy/archive/tags/Ashley+McGlone/">Ashley McGlone</category></item></channel></rss>
