{"id":3272,"date":"2013-07-06T00:01:00","date_gmt":"2013-07-06T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/07\/06\/weekend-scripter-a-little-powershell-help-here-please\/"},"modified":"2013-07-06T00:01:00","modified_gmt":"2013-07-06T00:01:00","slug":"weekend-scripter-a-little-powershell-help-here-please","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/weekend-scripter-a-little-powershell-help-here-please\/","title":{"rendered":"Weekend Scripter: A Little PowerShell Help Here&#8230;Please?"},"content":{"rendered":"<p><strong style=\"font-size: 12px\">Summary<\/strong><span style=\"font-size: 12px\">: Guest blogger, Matt Tisdale, talks about adding Help text to Windows PowerShell functions.<\/span>\nMicrosoft Scripting Guy, Ed Wilson, is here. Yesterday I introduced Matt Tisdale as the guest blogger. Guess what? He&rsquo;s back today!&nbsp; Dude!! Sweet!!! Here is Matt&rsquo;s post from yesterday: <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2013\/07\/05\/optimize-performance-of-ad-ds-queries-via-powershell.aspx\">Optimize Performance of AD DS Queries via PowerShell<\/a>. Today he discusses adding Help text to custom functions&hellip;\nI now have a few people at my company who are writing custom Windows PowerShell functions to help other IT team members and business employees. I am very excited to see this, and I always try to provide additional information to help these individuals make functions more beneficial and useful.\nOne of the best ways to make a function useful to others is to add Help text. Anyone who has used Windows PowerShell for more than five minutes is already familiar with the <strong>Get-Help<\/strong> cmdlet. If we want to learn how to use the <strong>Get-ADUser<\/strong> cmdlet, we simply run <strong>Get-Help Get-ADUser -detailed<\/strong>. The information that is displayed by <strong>Get-Help<\/strong> appears because the programmer who wrote <strong>Get-ADUser<\/strong> added the Help text into their script.\nLikewise, Help text can be added to any custom function quite easily. Let&#8217;s say you have a function named <strong>Get-FolderData<\/strong>. With just a few lines of script added to the function, other people can run <strong>Get-Help Get-FolderData -detailed<\/strong> and see exactly what the function does and how to use it.\nThere are a few ways you can add Help text, but to help maintain a consistent standard at my company, I recommend that everyone use the following standards:<\/p>\n<ol start=\"1\">\n<li>Start your Help text block immediately under the first line of script in your function.<\/li>\n<li>Open your Help text block with the characters <strong>&lt;#<\/strong>, and end the block with <strong>#&gt;<\/strong><\/li>\n<li>With your Help text, always include SYNOPSIS, DESCRIPTION, and EXAMPLE at a minimum.<\/li>\n<\/ol>\n<p>Let&#8217;s break this down a little&#8230;\nSo what is a Help text block? This is nothing more than a block of script that contains all of the data you want to display when <strong>Get-Help<\/strong> is used against your function. Here is a very simple example:<\/p>\n<p style=\"padding-left: 30px\">Function Get-FolderData() {<\/p>\n<p style=\"padding-left: 30px\">&lt;#<\/p>\n<p style=\"padding-left: 30px\">.SYNOPSIS<\/p>\n<p style=\"padding-left: 30px\">Retrieve specific information about one or more folders<\/p>\n<p style=\"padding-left: 30px\">.DESCRIPTION<\/p>\n<p style=\"padding-left: 30px\">This function can be used to read information about folder properties.<\/p>\n<p style=\"padding-left: 30px\">Some of the properties this function can read include size, when created,<\/p>\n<p style=\"padding-left: 30px\">last modified and many more.<\/p>\n<p style=\"padding-left: 30px\">.PARAMETER Path<\/p>\n<p style=\"padding-left: 30px\">This parameter contains the full path to the folder you wish to<\/p>\n<p style=\"padding-left: 30px\">display information for.<\/p>\n<p style=\"padding-left: 30px\">.EXAMPLE<\/p>\n<p style=\"padding-left: 30px\">Get-FolderData -Path &#8220;c:temptest1&#8221;<\/p>\n<p style=\"padding-left: 30px\">This command returns information for the folder c:temptest1<\/p>\n<p style=\"padding-left: 30px\">#&gt;<\/p>\n<p style=\"padding-left: 30px\">### CODE GOES HERE ###<\/p>\n<p style=\"padding-left: 30px\">}\nThat is all it takes. Pretty simple! Notice how the block starts with the characters <strong>&lt;#<\/strong> and ends with <strong>#&gt;<\/strong>? This is my preferred method for building a Help text block. All of the Help text that you want to display simply goes between these two character strings.\nThe next important thing to look for is Keyword headings. Take a look at .SYNOPSIS, .DESCRIPTION, and the other keywords in the previous Help text. Each of these keywords must be entered exactly as shown, including the preceding period. <strong>Get-Help<\/strong> looks for these keywords, and they determine how Help data is displayed on the screen.\nMake sure that you always include .SYNOPSIS, .DESCRIPTION, and .EXAMPLE at a minimum. Another keyword that will most likely be used in most of your functions is .PARAMETER. The .PARAMETER and .EXAMPLE keywords can be used as many times as you want.\nInstead of writing a book here about what each of these keywords are used for and all of the other remaining details related to Help text, I recommend that you check out the documentation already provided by Microsoft. To read all of the details about Help text, do either of the following:<\/p>\n<ul>\n<li>Check out <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/dd819489.aspx\" target=\"_blank\">about_Comment_Based_Help<\/a> in the Windows Dev Center<\/li>\n<li>Open Windows PowerShell and run <strong>Get-Help about_comment_based_help<\/strong><\/li>\n<\/ul>\n<p>Happy scripting!\n~Matt\nThank you, Matt. Way cool stuff. Join us tomorrow for one more guest post from Matt.\nI 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=\"http:\/\/blogs.technet.commailto: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: Guest blogger, Matt Tisdale, talks about adding Help text to Windows PowerShell functions. Microsoft Scripting Guy, Ed Wilson, is here. Yesterday I introduced Matt Tisdale as the guest blogger. Guess what? He&rsquo;s back today!&nbsp; Dude!! Sweet!!! Here is Matt&rsquo;s post from yesterday: Optimize Performance of AD DS Queries via PowerShell. Today he discusses adding [&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":[56,433,3,4,61,45],"class_list":["post-3272","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-guest-blogger","tag-matt-tisdale","tag-scripting-guy","tag-scripting-techniques","tag-weekend-scripter","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Guest blogger, Matt Tisdale, talks about adding Help text to Windows PowerShell functions. Microsoft Scripting Guy, Ed Wilson, is here. Yesterday I introduced Matt Tisdale as the guest blogger. Guess what? He&rsquo;s back today!&nbsp; Dude!! Sweet!!! Here is Matt&rsquo;s post from yesterday: Optimize Performance of AD DS Queries via PowerShell. Today he discusses adding [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3272","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=3272"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3272\/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=3272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=3272"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=3272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}