{"id":51933,"date":"2009-11-25T00:01:00","date_gmt":"2009-11-25T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2009\/11\/25\/hey-scripting-guy-whats-the-deal-with-the-dash-in-cmdlet-names\/"},"modified":"2009-11-25T00:01:00","modified_gmt":"2009-11-25T00:01:00","slug":"hey-scripting-guy-whats-the-deal-with-the-dash-in-cmdlet-names","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-whats-the-deal-with-the-dash-in-cmdlet-names\/","title":{"rendered":"Hey, Scripting Guy! What&#8217;s the Deal with the Dash in Cmdlet Names?"},"content":{"rendered":"<p><!-- AddThis Button BEGIN --><a class=\"addthis_button\" href=\"http:\/\/www.addthis.com\/bookmark.php?v=250&amp;pub=scriptingguys\"><img decoding=\"async\" alt=\"Bookmark and Share\" src=\"http:\/\/s7.addthis.com\/static\/btn\/v2\/lg-share-en.gif\" width=\"125\" height=\"16\"><\/a>     <br><\/p>\n<p><img decoding=\"async\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"><\/p>\n<p class=\"MsoNormal\">Hey, Scripting Guy! I enjoy using Windows PowerShell, but I do not like the two-word cmdlet names you created for everything. As a matter of fact, I <i>hate<\/i> the two-word cmdlet names because the dash (-) symbol is hard to type. I guess I will eventually get used to it, but you have to realize that Windows PowerShell as a tool for network administrators is really hard to use. I studied computer architecture and networking protocols at university&mdash;<i>not<\/i> typing. I don&rsquo;t suppose you can do anything about it now, but I just thought I would let off some steam. For a tool that is advertised to make things easier, it sure is hard to use. <\/p>\n<p class=\"MsoNormal\">&#8212; BW<\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\">Hello BW, <\/p>\n<p class=\"MsoNormal\">Microsoft Scripting Guy Ed Wilson here. It is dark as pitch. Not a star in the sky. Not a street light visible through the thick evening fog. I am trying to catch up on e-mail sent to the <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\"><font face=\"Segoe\">scripter@microsoft.com<\/font><\/a> e-mail alias and get ready for the approaching holiday season in the United States. Between now and the new year, Craig and I will only be working a few overlapping days, and we are not going to publish reruns through the holidays as has been done in the past. This means burning the midnight oil so to speak. I enjoy working in the evening. I am listening to <a href=\"http:\/\/en.wikipedia.org\/wiki\/Phil_collins\"><font face=\"Segoe\">Phil Collins<\/font><\/a> on my <a href=\"http:\/\/www.zune.net\/en-us\/products\/zunehd\/default.htm\"><font face=\"Segoe\">Zune HD<\/font><\/a>, and sipping a cup of blueberry tea. The sleeping Office Communicator icon in the notification area of my Window 7 Task Bar and dearth of meetings means I can be doubly productive, which is perfect because I need to write twice the number of Hey, Scripting Guy! posts during the next two weeks to meet my goal. <\/p>\n<p class=\"MsoNormal\">Anyway, BW, you seem to be averse to typing the dash symbol. You are not the first person who has mentioned this to me. If you really want to fix the problem, you can do it with a single-line command as shown here: <\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\"><font size=\"2\">gcm -CommandType cmdlet | % { Set-Alias ( $_.name -replace &#8220;-&#8220;,&#8221;&#8221;) $_.name }<\/p>\n<p><\/font><\/font><\/span><\/p>\n<p class=\"MsoNormal\"><b>GCM<\/b> is the alias for the Windows PowerShell <b>Get-Command<\/b> cmdlet. An alias allows you to create a shortcut name for a command. Do this for commands that are hard to type, too long to type, or too difficult to remember. By using aliases, you can completely customize the way that you interact with Windows PowerShell. To see a list of the available aliases, use the <b>Get-Alias<\/b> cmdlet, which will list aliases that are created by Windows PowerShell as well as any aliases you may have created yourself. <\/p>\n<p class=\"MsoNormal\">Truncated output from the <b>Get-Alias<\/b> cmdlet is seen just below. You will notice that the first alias that is listed is the percent sign. It is an alias for the <b>ForEach-Object<\/b> cmdlet and was used in the code we used to remove the dash from all the cmdlet names. The next alias, the question mark, is also a commonly used alias. The problem a number of people coming from a DOS\/VBScript background have with the question mark alias is that command-line utilities often used the question mark for help. Some of the new aliases we created can also be seen. <b>AddComputer<\/b>, <b>AddContent<\/b>, and others are the standard command names with the dash removed. These are shown here:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\"><font size=\"2\">PS C:&gt; Get-Alias<\/p>\n<p>CommandType<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Definition<br>&#8212;&#8212;&#8212;&#8211;<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8212;-<br>Alias<span>&nb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bsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span>Add-Type<br>Alias<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>asnp<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Add-PSSnapIn<br>Alias<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>cat<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Get-Content<\/p>\n<p><\/font><\/font><\/span><\/p>\n<p class=\"MsoNormal\">The problem with simply executing a command inside the Windows PowerShell console is that once you close and re-open Windows PowerShell console, the aliases are gone. They will need to be recreated each time that you open Windows PowerShell. This is shown by the output seen here:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\"><font size=\"2\">Windows PowerShell<br>Copyright (C) 2009 Microsoft Corporation. All rights reserved.<\/p>\n<p>PS C:&gt; Get-Alias<\/p>\n<p>CommandType<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Definition<br>&#8212;&#8212;&#8212;&#8211;<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8212;-<br>Alias<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>%<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n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&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Set-Location<br>Alias<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>chdir<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;<\/span>Set-Location<\/p>\n<p><\/font><\/font><\/span><\/p>\n<p class=\"MsoNormal\">One thing you can do to make sure you always have the aliases you wish is to save your command history after you have run the command to create the aliases. You can save your command history to an XML file by using the following command:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">Get-History |<br>Export-Clixml -Path c:fsohistory.xml<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">The saved XML file can be viewed in XML Notepad as seen in the following image. The thing to keep in mind about this technique is you want to make sure that you have a clean command history by closing the Windows PowerShell console and re-opening it:<\/p>\n<p class=\"Fig-Graphic\"><img decoding=\"async\" title=\"Image of XML file being viewed with XML Notepad\" alt=\"Image of XML file being viewed with XML Notepad\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/november\/hey1125\/hsg-11-25-09-01.jpg\" width=\"600\" height=\"425\"><\/p>\n<p class=\"MsoNormal\"><br>After you have your newly created history.xml file, you need only to import the file and execute each of the commands in your command history. You can do this by using the following command:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">Import-Clixml C:fsohistory.xml |<br>add-history -passthru | <br>foreach-object {invoke-history}<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">The use of this command is seen here. Notice that when the history is invoked, the command is displayed on the command line. The <b>Get-Alias<\/b> cmdlet is then used to list the last four alises, which are our newly created aliases. <\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\"><font size=\"2\">PS C:&gt; Import-Clixml C:fsohistory.xml |<br>&gt;&gt; add-history -passthru |<br>&gt;&gt; foreach-object {invoke-history}<br>&gt;&gt;<br>gcm -CommandType cmdlet | % { Set-Alias ( $_.name -replace &#8220;-&#8220;,&#8221;&#8221;) $_.name }<br>PS C:&gt; Get-Alias | select -Last 4<\/p>\n<p>CommandType<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Definition<br>&#8212;&#8212;&#8212;&#8211;<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb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/span>Write-Verbose<br>Alias<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>WriteWarning<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Write-Warning<\/p>\n<p><br>PS C:&gt;<\/p>\n<p><\/font><\/font><\/span><\/p>\n<p class=\"MsoNormal\">One use of the export\/import command history technique would be in a setting where you were not permitted to run scripts. Because the Windows PowerShell profile is a script, the profile script will not run if the command execution policy is set to <b>Restricted<\/b>. <\/p>\n<p class=\"MsoNormal\">The best place to manage aliases, of course, is to use the Windows PowerShell profile. Our Windows PowerShell profile from <a href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2009\/11\/24\/hey-scripting-guy-november-24-2009.aspx\">yesterday<\/a> has been updated with the &ldquo;remove the dash&rdquo; command and a couple of additional aliases. The Profile.ps1 script is seen here. <\/p>\n<p class=\"CodeBlockScreenedHead\"><strong>Profile.ps1<\/strong><\/p>\n<p class=\"CodeBlockScreened\"><font face=\"Lucida Sans Typewriter\"># HSG_Profile_11_24_09.ps1<br># HSG-11-24-09<br># Ed Wilson, MSFT, 11\/18\/2009<br># Version 1.0<\/p>\n<p># *** Variables ***<br>New-Variable -Name ProfileFolder -Value (Split-Path $PROFILE -Parent) `<br><span>&nbsp;&nbsp; <\/span>-Description MrEd_Variable<br>New-Variable -Name IseProfile `<br><span>&nbsp;&nbsp; <\/span>-Value (Join-Path -Path (Split-Path $PROFILE -Parent) `<br><span>&nbsp;&nbsp; <\/span>-ChildPath Microsoft.PowerShellISE_profile.ps1) `<br><span>&nbsp;&nbsp; <\/span>-Description MrEd_Variable<br>New-Variable -Name MyComputers -Value Hyperv,Win7-PC -Description MrEd_Variable<br>New-Variable -name temp -value $([io.path]::gettemppath()) -Description MrEd_Variable<br>Set-Variable -Name MaximumHistoryCount -Value 128 -Description MrEd_Variable<\/p>\n<p># *** Alias ***<br>Get-Command -CommandType cmdlet | <br>Foreach-Object { <br><span>&nbsp;<\/span>Set-Alias -name ( $_.name -replace &#8220;-&#8220;,&#8221;&#8221;) -value $_.name -description MrEd_Alias<br>} #end Get-Command<br>New-Alias -name gh -value Get-Help -description MrEd_Alias<br>New-Alias -name i -value Invoke-History -description MrEd_Alias<\/p>\n<p># *** PS Drive ***<\/p>\n<p># *** Function ***<\/font><\/p>\n<p class=\"MsoNormal\">Before transferring the &ldquo;remove the dashes&rdquo; command to the Windows PowerShell profile, I modified it by removing the aliases from the command (I know, it seems a little strange to remove aliases from a command that creates aliases) because as a best practice, you do not want to use aliases or positional arguments in scripts. Though it is possible to add aliases, it is also possible to remove aliases&mdash;even aliases that are included by default. Suppose, for example, that the use of the question mark for the <b>Where-Object<\/b> cmdlet really bugs you, and you would rather use it for the <b>Get-Help <\/b>cmdlet. No problem. You just modify the value of the alias. This is seen here:<\/p>\n<p class=\"CodeBlockScreened\"><font face=\"Lucida Sans Typewriter\">PS C:&gt; Set-Alias -Name ? -Value Get-Help -Force -Option allscope<br>PS C:&gt;<\/font><\/p>\n<p class=\"MsoNormal\">Maybe you really do not like the <b>%<\/b> alias at all. You can remove the alias by using the <b>Remove-Item<\/b> cmdlet. This is seen here. <\/p>\n<p class=\"CodeBlockScreened\"><font face=\"Lucida Sans Typewriter\">PS C:&gt; Remove-Item alias:% -Force<br>PS C:&gt;<\/font><\/p>\n<p class=\"MsoNormal\">All this is to say that when using an alias, you never know if it is going to exist or not, unless you totally control the environment. As a best practice, do <i>not<\/i> use aliases in a script.<span>&nbsp; <\/span><\/p>\n<p class=\"MsoNormal\">Two aliases that I like to use are <b>gh<\/b> for the <b>Get-Help<\/b> cmdlet and <b>i<\/b> for the <b>Invoke-History<\/b> cmdlet. When creating new aliases, I like to populate the description parameter. This is seen here:<\/p>\n<p class=\"CodeBlockScreened\"><font face=\"Lucida Sans Typewriter\">New-Alias -name gh -value Get-Help -description MrEd_Alias<br>New-Alias -name i -value Invoke-History -description MrEd_Alias <\/font><\/p>\n<p class=\"MsoNormal\">The advantage of populating the <b>description<\/b> parameter for the alias is it makes it easy to retrieve my custom aliases. I can do this by using the <b>Get-Alias<\/b> cmdlet to retrieve all the defined aliases, and pipe the results to the <b>Where-Object<\/b> cmdlet. The command and the truncated results are shown here:<\/p>\n<p class=\"CodeBlockScreened\"><font face=\"Lucida Sans Typewriter\">PS C:&gt; Get-Alias | Where-Object { $_.description -eq &#8216;MrEd_Alias&#8217;}<\/p>\n<p>CommandType<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;<\/span>Definition<br>&#8212;&#8212;&#8212;&#8211;<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Add-History<\/font><\/p>\n<p class=\"MsoNormal\">You might be wondering: &ldquo;We just added a bunch of new aliases. Will we run out of space?&rdquo; The answer is: Yes, it is possible. The <b>$maxAliasCount<\/b> variable is set to 4096, but you can change that value if you need to. It is unlikely that you will need to modify this value. We still have plenty of room as shown here:<\/p>\n<p class=\"CodeBlockScreened\"><font face=\"Lucida Sans Typewriter\">PS C:&gt; $MaximumAliasCount<br>4096<br>PS C:&gt; Get-Alias | Measure-Object<\/p>\n<p>Count<span>&nbsp;&nbsp;&nbsp; <\/span>: 374<br>Average<span>&nbsp; <\/span>:<br>Sum<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>:<br>Maximum<span>&nbsp; <\/span>:<br>Minimum<span>&nbsp; <\/span>:<br>Property :<\/p>\n<p>PS C:&gt;<\/font><\/p>\n<p class=\"MsoNormal\">Of course, BW, our Windows PowerShell profile is really beginning to take shape at this point. We will add to our profile tomorrow as Windows PowerShell Profile Week continues. <\/p>\n<p class=\"MsoNormal\">If you want to know exactly what we will be looking at tomorrow, follow us on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\"><font face=\"Segoe\">Twitter<\/font><\/a> or <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send e-mail to us at <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\" target=\"_blank\"><font face=\"Segoe\">scripter@microsoft.com<\/font><\/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, keep on scripting!<br>&nbsp;<\/p>\n<p>&lt;<\/p>\n<p>p style=&#8221;MARGIN-LEFT: 0in&#8221;&gt;<b><span>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/span><\/b><\/p>\n<p><!-- AddThis Button END -->!&#8211;&gt;<\/p>\n<p>!&#8211;&gt;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! I enjoy using Windows PowerShell, but I do not like the two-word cmdlet names you created for everything. As a matter of fact, I hate the two-word cmdlet names because the dash (-) symbol is hard to type. I guess I will eventually get used to it, but you have to realize [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[51,144,3,4,45],"class_list":["post-51933","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-getting-started","tag-profiles","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! I enjoy using Windows PowerShell, but I do not like the two-word cmdlet names you created for everything. As a matter of fact, I hate the two-word cmdlet names because the dash (-) symbol is hard to type. I guess I will eventually get used to it, but you have to realize [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/51933","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\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=51933"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/51933\/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=51933"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=51933"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=51933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}