{"id":590,"date":"2014-10-04T00:01:00","date_gmt":"2014-10-04T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/10\/04\/weekend-scripter-change-powershell-get-help-to-display-examples\/"},"modified":"2014-10-04T00:01:00","modified_gmt":"2014-10-04T00:01:00","slug":"weekend-scripter-change-powershell-get-help-to-display-examples","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/weekend-scripter-change-powershell-get-help-to-display-examples\/","title":{"rendered":"Weekend Scripter: Change PowerShell Get-Help to Display Examples"},"content":{"rendered":"<p><b style=\"font-size:12px\">Summary<\/b><span style=\"font-size:12px\">: Microsoft Scripting Guy, Ed Wilson, talks about changing the <\/span><b style=\"font-size:12px\">Get-Help<\/b><span style=\"font-size:12px\"> cmdlet so it always displays examples.<\/span><\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. For the last several weeks, I have been working on a project at work. The documentation team talked to customers to see how they were using Windows PowerShell, and to see how and when they used Help. The project has been a lot of fun, and it has been very interesting. The other day, we were discussing the results of the survey we conducted, and one of the managers mentioned that one customer said that he wished when he typed <b>Get-Help<\/b>, it would always display the examples. In fact, several customers said that the examples were the most helpful portion of the Help. I chimed in and said, &ldquo;Dude, that is easy.&rdquo;<\/p>\n<p>The manager said, &ldquo;Huh?&rdquo;<\/p>\n<p>I said, &quot;I can easily fix the <b>Get-Help<\/b> cmdlet so that by default, it displays examples.&quot;<\/p>\n<p>The manager said, &ldquo;Really?&rdquo;<\/p>\n<p>I said, &ldquo;Dude, it is like a one-liner. I mean, it is like less than a one-liner. I mean, I can fix any cmdlet and make it do what I want it to do.&rdquo;<\/p>\n<p>The manager said, &ldquo;Really?&rdquo;<\/p>\n<p>I said, &ldquo;In fact, that is a great idea. I will write a Hey, Scripting Guy! Blog post about it.&rdquo;<\/p>\n<p>And so I did&#8230;<\/p>\n<h2>Making Get-Help more helpful<\/h2>\n<p>Making <b>Get-Help<\/b> more helpful has always been a capability of Windows PowerShell. In fact, in my Windows PowerShell&nbsp;1.0 Step by Step book, I included a function I called <b>Get-MoreHelp<\/b>. I even created an alias that I named <b>GMH<\/b>. The function accepts an input (the name of a cmdlet) and then calls <b>Get-Help<\/b> with the <b>&ndash;Full<\/b> parameter. Here is the <b>Get-MoreHelp<\/b> function:<\/p>\n<p style=\"margin-left:30px\">Function Get-MoreHelp<\/p>\n<p style=\"margin-left:30px\">{<\/p>\n<p style=\"margin-left:30px\">&nbsp;Get-Help $args[0] -full |<\/p>\n<p style=\"margin-left:30px\">&nbsp;more<\/p>\n<p style=\"margin-left:30px\">} #End Get-MoreHelp<\/p>\n<p style=\"margin-left:30px\">New-Alias -name gmh -value Get-MoreHelp -Option allscope<\/p>\n<p>I then added this function to my Windows PowerShell profile, and now I have the <b>Get-Help<\/b> cmdlet working the way I want it to work.<\/p>\n<h2>Making Get-Help provide examples without scripting<\/h2>\n<p>One of the really cool features introduced in Windows PowerShell&nbsp;3.0 was the <b>$PSDefaultParameterValues<\/b> automatic variable. This variable accepts a hash table that I can use to specify new default parameter values for any Windows PowerShell cmdlet. It is documented in the TehcNet Library: <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/hh847819.aspx\" target=\"_blank\">about_Parameters_Default_Values<\/a>. In addition, my friend, Windows PowerShell MVP, David Moravec, wrote a really cool guest blog post that talks about how he uses this feature to simplify his scripts: <a href=\"\/b\/heyscriptingguy\/archive\/2012\/12\/03\/use-powershell-default-parameter-values-to-simplify-scripts.aspx\" target=\"_blank\">Use PowerShell Default Parameter Values to Simplify Scripts<\/a>.<\/p>\n<p>How hard is it to use <b>$PSDefaultParameterValues<\/b>? Well, it is easier to use than to type it. (This is because in Windows PowerShell, we have Tab completion. Microsoft Word does not have Tab completion.) I provide a hash table with the cmdlet name, the parameter, and a value. Here is what I used to make <b>Get-Help<\/b> automatically provide examples:<\/p>\n<p style=\"margin-left:30px\">$PSDefaultParameterValues = @{&#039;Get-Help:examples&#039;=$true}<b><\/b><\/p>\n<p>Now when I type <b>Get-Help<\/b> and provide a cmdlet name, Help automatically returns those really cool examples that everyone loves. This technique is shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-10-4-14-01.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-10-4-14-01.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>If I like this, I add the command to my Windows PowerShell profile. If I want to override the behavior, I supply additional parameters (such as <b>&ndash;Full<\/b>). This command is shown here:<\/p>\n<p style=\"margin-left:30px\">Get-Help Get-Process -full | more<\/p>\n<p>Well, that is it. Talk to you tomorrow when I will have more way 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><b>Ed Wilson, Microsoft Scripting Guy<\/b><span style=\"font-size:12px\">&nbsp;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about changing the Get-Help cmdlet so it always displays examples. Microsoft Scripting Guy, Ed Wilson, is here. For the last several weeks, I have been working on a project at work. The documentation team talked to customers to see how they were using Windows PowerShell, and to see [&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,61,45],"class_list":["post-590","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-getting-started","tag-scripting-guy","tag-scripting-techniques","tag-weekend-scripter","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about changing the Get-Help cmdlet so it always displays examples. Microsoft Scripting Guy, Ed Wilson, is here. For the last several weeks, I have been working on a project at work. The documentation team talked to customers to see how they were using Windows PowerShell, and to see [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/590","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=590"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/590\/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=590"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=590"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}