{"id":2453,"date":"2013-12-09T00:01:00","date_gmt":"2013-12-09T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/12\/09\/see-how-naming-makes-powershell-easy-to-learn\/"},"modified":"2013-12-09T00:01:00","modified_gmt":"2013-12-09T00:01:00","slug":"see-how-naming-makes-powershell-easy-to-learn","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/see-how-naming-makes-powershell-easy-to-learn\/","title":{"rendered":"See How Naming Makes PowerShell Easy to Learn"},"content":{"rendered":"<p><strong>Summary<\/strong>: Microsoft Scripting Guy, Ed Wilson, shares an excerpt from his book, Windows PowerShell 3.0 Step by Step, which explains how the Windows PowerShell naming convention makes it easy to learn.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. Today I am happy to provide you with an excerpt from my book, <a href=\"http:\/\/www.amazon.com\/Windows-PowerShell-3-0-Step\/dp\/0735663394\/ref=tmm_pap_title_0?ie=UTF8&amp;qid=1383770622&amp;sr=8-1\" target=\"_blank\">Windows PowerShell 3.0 Step by Step<\/a>, published by Microsoft Press.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7851.Step%20by%20Step%20book.jpg\"><img decoding=\"async\" title=\"Image of book cover\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7851.Step%20by%20Step%20book.jpg\" alt=\"Image of book cover\" \/><\/a><\/p>\n<p>One of the great things about Windows PowerShell is the verb&ndash;noun naming convention. In Windows PowerShell, the verbs indicate an action to perform, such as <strong>Set<\/strong> to make a change or <strong>Get<\/strong> to retrieve a value. The noun indicates the item with which to work, such as a process or a service.<\/p>\n<p>By mastering the verb&ndash;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 <strong>Get<\/strong> to<em> <\/em>retrieve information, you can surmise that the command might very well be <strong>Get-Process<\/strong>. To obtain information about services, you try <strong>Get-Service<\/strong>&hellip;and once again, you are correct.<\/p>\n<p class=\"Readeraidonly\" style=\"padding-left: 30px\"><strong>Note&nbsp;<\/strong> When you are &ldquo;guessing&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 <strong>Get-Service<\/strong>, <strong>Get-Process<\/strong>, and not <strong>Get-Services<\/strong> or <strong>Get-Processes<\/strong>.<\/p>\n<p>To see the list of approved verbs, use the <strong>Get-Verb<\/strong> cmdlet. There are 98 approved verbs in Windows PowerShell&nbsp;3.0. This number increases the 96 approved verbs from Windows PowerShell&nbsp;2.0 by only two new verbs. The new verbs are <strong>Use<\/strong><em> <\/em>and <strong>Unprotect<\/strong><em>. <\/em>This is shown in the command that follows, where the <strong>Measure-Object<\/strong> cmdlet returns the count of the verbs:<\/p>\n<p class=\"CodeBlock\" style=\"padding-left: 30px\">PS C:\\&gt; (Get-Verb | Measure-Object).count<br \/> 98<\/p>\n<h2>Analyzing Windows PowerShell verb grouping<\/h2>\n<p>With nearly 100 verbs, you may be asking yourself, &ldquo;How does an array of 100 verbs assist in learning Windows PowerShell?&rdquo; You would be correct in asking that question. Nearly 100 unrelated items are 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:<\/p>\n<p class=\"CodeBlock\" style=\"padding-left: 30px\">PS C:\\&gt; <strong>Get-Verb<\/strong> | where group -match &#8216;common&#8217; | <strong>Format-Wide<\/strong> verb -auto<br \/> Add&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Clear&nbsp; &nbsp;&nbsp;&nbsp;Close&nbsp;&nbsp;&nbsp;&nbsp; Copy&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Enter&nbsp;&nbsp;&nbsp; Exit&nbsp;&nbsp;&nbsp;&nbsp; Find&nbsp;&nbsp;&nbsp;&nbsp; Format&nbsp;&nbsp; Get<br \/> Hide&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Join&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Lock&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Move&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; New&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Open&nbsp;&nbsp;&nbsp;&nbsp; Optimize Pop&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Push<br \/> Redo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Remove&nbsp;&nbsp;&nbsp; Rename&nbsp;&nbsp;&nbsp; Reset&nbsp;&nbsp;&nbsp;&nbsp; Resize&nbsp;&nbsp; Search&nbsp;&nbsp; Select&nbsp;&nbsp; Set&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Show<br \/> Skip&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Split&nbsp;&nbsp;&nbsp;&nbsp; Step&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Switch&nbsp;&nbsp;&nbsp; Undo&nbsp;&nbsp;&nbsp;&nbsp; Unlock&nbsp;&nbsp; Watch<\/p>\n<p>The pattern to the verbs emerges when analyzing the verbs: 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.<\/p>\n<p>By using the Windows PowerShell verb grouping, you can determine where to focus your efforts. The following command lists the Windows PowerShell verb grouping:<\/p>\n<p class=\"CodeBlock\" style=\"padding-left: 30px\">PS C:\\&gt; <strong>Get-Verb<\/strong> | select group -Unique<br \/> Group<br \/> &#8212;&#8211;<br \/> Common<br \/> Data<br \/> Lifecycle<br \/> Diagnostic<br \/> Communications<br \/> Security<br \/> Other<\/p>\n<h2>Analyzing Windows PowerShell verb distribution<\/h2>\n<p>Another way to get a handle on the Windows PowerShell cmdlets, is to analyze the verb distribution. Although there are nearly 100 approved verbs (not to mention rogue developers, who use unapproved verbs), only a fraction of them are utilized repeatedly&mdash;and some of them are not used at all in a standard Windows PowerShell installation. By using the <strong>Group-Object<\/strong> (<strong>group<\/strong> is an alias) and the <strong>Sort-Object<\/strong> cmdlet (<strong>sort<\/strong> is an alias), the distribution of the cmdlets quickly becomes evident. The following command shows the verb distribution:<\/p>\n<p class=\"CodeBlock\" style=\"padding-left: 30px\">Get-Command -CommandType cmdlet | group verb | sort count &ndash;Descending<\/p>\n<p>The command and the output associated with the command are shown in the following image:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3108.hsg-12-9-13-1.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3108.hsg-12-9-13-1.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p class=\"Num-Caption\">The preceding output makes it clear that most cmdlets only use a few of the verbs. In fact, most of the cmdlets use only one of ten verbs. This is shown here:<\/p>\n<p class=\"CodeBlock\" style=\"padding-left: 30px\">PS C:\\&gt; Get-Command -CommandType cmdlet | group verb | sort count -Descending | select -First 10<br \/> Count Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Group<br \/> &#8212;&#8211; &#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8211;<br \/> &nbsp;&nbsp; 94 Get&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {Get-Acl, Get-Alias, Get-AppLockerFileInformation&#8230;<br \/> &nbsp;&nbsp; 48 Set&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;{Set-Acl, Set-Alias, Set-AppLockerPolicy, Set-Aut&#8230;<br \/> &nbsp;&nbsp; 38 New&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {New-Alias, New-AppLockerPolicy, New-CertificateN&#8230;<br \/> &nbsp;&nbsp; 30 Remove&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {Remove-AppxProvisionedPackage, Remove-BitsTransf&#8230;<br \/> &nbsp;&nbsp; 15 Add&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {Add-AppxProvisionedPackage, Add-BitsFile, Add-Ce&#8230;<br \/> &nbsp;&nbsp; 11 Invoke&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {Invoke-BpaModel, Invoke-CimMethod, Invoke-Comman&#8230;<br \/> &nbsp;&nbsp; 11 Import&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {Import-Alias, Import-Certificate, Import-Clixml,&#8230;<br \/> &nbsp;&nbsp; 11 Export&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {Export-Alias, Export-Certificate, Export-Clixml,&#8230;<br \/> &nbsp;&nbsp; 10 Test&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {Test-AppLockerPolicy, Test-Certificate, Test-Com&#8230;<br \/> &nbsp;&nbsp; 10 Enable&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {Enable-ComputerRestore, Enable-JobTrigger, Enabl&#8230;<\/p>\n<p>In fact, of 436 cmdlets, 278 of the cmdlets use only one of ten verbs. This is shown here:<\/p>\n<p class=\"CodeBlock\" style=\"padding-left: 30px\">PS C:\\&gt; (Get-Command -CommandType cmdlet | measure).count<br \/> 436<br \/> PS C:\\&gt; $count = 0 ; Get-Command -CommandType cmdlet | group verb | sort count -Desce<br \/> nding | select -First 10 | % { $count += $_.count ; $count }<br \/> 94<br \/> 142<br \/> 180<br \/> 210<br \/> 225<br \/> 236<br \/> 247<br \/> 258<br \/> 268<br \/> 278<\/p>\n<p>Therefore, 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&nbsp;3.0.<\/p>\n<p>That is all there is to using Windows PowerShell to explore cmdlet naming. Join me tomorrow when I will talk about more cool Windows PowerShell stuff.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><strong>Ed Wilson, Microsoft Scripting Guy<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, shares an excerpt from his book, Windows PowerShell 3.0 Step by Step, which explains how the Windows PowerShell naming convention makes it easy to learn. Microsoft Scripting Guy, Ed Wilson, is here. Today I am happy to provide you with an excerpt from my book, Windows PowerShell 3.0 Step [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[51,3,4,45],"class_list":["post-2453","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-getting-started","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, shares an excerpt from his book, Windows PowerShell 3.0 Step by Step, which explains how the Windows PowerShell naming convention makes it easy to learn. Microsoft Scripting Guy, Ed Wilson, is here. Today I am happy to provide you with an excerpt from my book, Windows PowerShell 3.0 Step [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2453","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=2453"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2453\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=2453"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=2453"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=2453"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}