{"id":122,"date":"2019-01-10T09:36:26","date_gmt":"2019-01-10T09:36:26","guid":{"rendered":"https:\/\/www.atlanta247.com\/blog\/?p=122"},"modified":"2019-01-09T16:11:42","modified_gmt":"2019-01-09T16:11:42","slug":"commenting-your-code","status":"publish","type":"post","link":"https:\/\/www.atlanta247.com\/blog\/2019\/01\/10\/commenting-your-code\/","title":{"rendered":"Commenting your Code"},"content":{"rendered":"\n<p>There is nothing more frustrating than looking at Powershell code from someone else &#8211; who didn&#8217;t bother to comment the code.   1000 lines without a clue of what is happening, unless you understand the relevance of each command in context.   Uhg. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignright\"><img loading=\"lazy\" decoding=\"async\" width=\"299\" height=\"277\" src=\"https:\/\/www.atlanta247.com\/blog\/wp-content\/uploads\/2019\/01\/poundsign-1.png\" alt=\"\" class=\"wp-image-124\" srcset=\"https:\/\/www.atlanta247.com\/blog\/wp-content\/uploads\/2019\/01\/poundsign-1.png 299w, https:\/\/www.atlanta247.com\/blog\/wp-content\/uploads\/2019\/01\/poundsign-1-150x139.png 150w\" sizes=\"auto, (max-width: 299px) 100vw, 299px\" \/><\/figure><\/div>\n\n\n\n<p>In Powershell one can use the # symbol (Pound or Hashtag) to denote information that is &#8220;notes&#8221; and not part of the code.     <\/p>\n\n\n\n<p>For example I will denote section headers with large blocks of # signs for visibility: <br><\/p>\n\n\n\n<p style=\"color:#07932a\" class=\"has-text-color\">\n\n############################################<br>#<br>#  This section is about commenting your code<br>#<br>############################################<\/p>\n\n\n\n<p>and smaller notes with a smaller comment:<\/p>\n\n\n\n<p style=\"color:#07932a\" class=\"has-text-color\">####################<br>##  Loop through this <\/p>\n\n\n\n<p>You can also add a # at the end to comment out a piece &#8211; for example if I use a whatif for testing but don&#8217;t want it there once the code is &#8220;production&#8221;.  <\/p>\n\n\n\n<p>$user = Get-Aduser -name $inputname  #-whatif\n\n<\/p>\n\n\n\n<p>NOTE:  Whereever the #starts, the code ends. <\/p>\n\n\n\n<p>In additon you can use a &#8220;Regions&#8221; to denote sections of your code.  Like college football conferences&#8230; but with less gerrymandering. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.atlanta247.com\/blog\/wp-content\/uploads\/2019\/01\/fbs-conferences.jpg\" alt=\"\" class=\"wp-image-125\" width=\"442\" height=\"265\" srcset=\"https:\/\/www.atlanta247.com\/blog\/wp-content\/uploads\/2019\/01\/fbs-conferences.jpg 1000w, https:\/\/www.atlanta247.com\/blog\/wp-content\/uploads\/2019\/01\/fbs-conferences-150x90.jpg 150w, https:\/\/www.atlanta247.com\/blog\/wp-content\/uploads\/2019\/01\/fbs-conferences-300x180.jpg 300w, https:\/\/www.atlanta247.com\/blog\/wp-content\/uploads\/2019\/01\/fbs-conferences-768x461.jpg 768w\" sizes=\"auto, (max-width: 442px) 100vw, 442px\" \/><\/figure><\/div>\n\n\n\n<p>To do this we use the # sign and the word &#8220;region&#8221; followed by a description to start the section: <\/p>\n\n\n\n<p style=\"color:#0921fb\" class=\"has-text-color\">#region Our Variables<\/p>\n\n\n\n<p> And then # and &#8220;endregion&#8221; to end the section.  <\/p>\n\n\n\n<p style=\"color:#0921fb\" class=\"has-text-color\">#endregion<\/p>\n\n\n\n<p>Most powershell editors, like PowerGui Script editor, will then allow you to collapse the region &#8211; makes browsing over sections of code:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"537\" height=\"376\" src=\"https:\/\/www.atlanta247.com\/blog\/wp-content\/uploads\/2019\/01\/regions.png\" alt=\"\" class=\"wp-image-126\" srcset=\"https:\/\/www.atlanta247.com\/blog\/wp-content\/uploads\/2019\/01\/regions.png 537w, https:\/\/www.atlanta247.com\/blog\/wp-content\/uploads\/2019\/01\/regions-150x105.png 150w, https:\/\/www.atlanta247.com\/blog\/wp-content\/uploads\/2019\/01\/regions-300x210.png 300w\" sizes=\"auto, (max-width: 537px) 100vw, 537px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>I hope you find this useful. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>There is nothing more frustrating than looking at Powershell code from someone else &#8211; who didn&#8217;t bother to comment the code. 1000 lines without a clue of what is happening, unless you understand the relevance of each command in context. Uhg. In Powershell one can use the # symbol (Pound or Hashtag) to denote information &hellip; <a href=\"https:\/\/www.atlanta247.com\/blog\/2019\/01\/10\/commenting-your-code\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Commenting your Code<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[8],"tags":[],"class_list":["post-122","post","type-post","status-publish","format-standard","hentry","category-powershell"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.atlanta247.com\/blog\/wp-json\/wp\/v2\/posts\/122","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.atlanta247.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.atlanta247.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.atlanta247.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.atlanta247.com\/blog\/wp-json\/wp\/v2\/comments?post=122"}],"version-history":[{"count":1,"href":"https:\/\/www.atlanta247.com\/blog\/wp-json\/wp\/v2\/posts\/122\/revisions"}],"predecessor-version":[{"id":127,"href":"https:\/\/www.atlanta247.com\/blog\/wp-json\/wp\/v2\/posts\/122\/revisions\/127"}],"wp:attachment":[{"href":"https:\/\/www.atlanta247.com\/blog\/wp-json\/wp\/v2\/media?parent=122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.atlanta247.com\/blog\/wp-json\/wp\/v2\/categories?post=122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.atlanta247.com\/blog\/wp-json\/wp\/v2\/tags?post=122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}