{"id":586,"date":"2018-06-11T08:00:27","date_gmt":"2018-06-11T14:00:27","guid":{"rendered":"https:\/\/practicalpowershell.com\/?p=586"},"modified":"2020-03-14T16:40:28","modified_gmt":"2020-03-14T22:40:28","slug":"no-commenting-not-in-powershell","status":"publish","type":"post","link":"https:\/\/practicalpowershell.com\/no-commenting-not-in-powershell\/","title":{"rendered":"No Comment(ing)? Not in PowerShell"},"content":{"rendered":"<p><a href=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Comments.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Comments.jpg?resize=150%2C150&#038;ssl=1\" alt=\"\" width=\"150\" height=\"150\" class=\"alignleft size-thumbnail wp-image-587\" srcset=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Comments.jpg?resize=150%2C150&amp;ssl=1 150w, https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Comments.jpg?resize=100%2C100&amp;ssl=1 100w, https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Comments.jpg?zoom=2&amp;resize=150%2C150&amp;ssl=1 300w, https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Comments.jpg?zoom=3&amp;resize=150%2C150&amp;ssl=1 450w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/a>Writing a script can be hard, making it reusable a bit harder and having someone else understand it&#8217;s purpose one of the hardest things you can do. To make your life and their life easier, the use of Comments is an easy way to enhance or augment a script. Below are a few examples of Commenting in PowerShell, the list is not exhaustive, but merely instructive.<BR><br \/>\n<u>Examples of Comments<\/u><BR><br \/>\n<em>Script Sections<\/em><BR><br \/>\nOne way to help someone parse a script and its purpose is to label sections of the script &#8211; variables, functions, main body, etc. Like so:<br \/>\n[sourcecode language=&#8221;powershell&#8221;]<br \/>\n# Variables<br \/>\n$NumberOfMailboxes = 0<br \/>\n$Failed = $False<br \/>\n$UserCount = 0<br \/>\n# Email Process<br \/>\nSend-MailMessage -To $To -From $From -Subject $Subject -Bodyashtml -Body $Body<br \/>\nSMTPServer $SMTPServer -Credential $SMTPCred -Port $Port -UseSsl<br \/>\n[\/sourcecode]<br \/>\nComments can also be used to provide a detailed description of the script and is usually placed at the beginning of your script:<br \/>\n[sourcecode language=&#8221;powershell&#8221;]<br \/>\n##########################################################<br \/>\n# SCRIPT DETAILS<br \/>\n# This script drives a menu to run Active Directory health check scripts.<br \/>\n# #<br \/>\n# SCRIPT VERSION HISTORY<br \/>\n# Current Version : 1.5<br \/>\n# Change Log<br \/>\n# :1.5 &#8211; fixed bugs, improve reporting<br \/>\n# : 1.4 &#8211; Added GPO check, fixed DNSLint issues<br \/>\n# : 1.3 &#8211; Tweaks and bug fixes<br \/>\n# : 1.2 &#8211; Removed deprecated tools<br \/>\n# : 1.1 &#8211; Added more AD Information and a fix for remote PS<br \/>\n# : 1.0 &#8211; First version<br \/>\n#<br \/>\n# OTHER SCRIPT<br \/>\n# Wish list : More tests, change some tests to export to HTML<br \/>\n# Rights Required : Enterprise Admin \/ Domain Admin<br \/>\n# Author : Damian Scoles<br \/>\n# My Blog : http:\/\/justaucguy.wordpress.com<br \/>\n#<br \/>\n# Disclaimer: You are on your own. This was not written by, supported<br \/>\n# by, or endorsed by Microsoft.<br \/>\n#<br \/>\n# EXECUTION<br \/>\n#. \\ActiveDirectoryHealthCheckMenu.PS1<br \/>\n#<br \/>\n##########################################################<br \/>\n[\/sourcecode]<br \/>\nComments can also be used to describe a function&#8217;s purpose:<BR><br \/>\nThis function checks for hotfixes needed in order to install corporate applications<br \/>\n[sourcecode language=&#8221;powershell&#8221;]<br \/>\nFunction HotfixCheck {<br \/>\n# Check to see if the hot fix is installed<br \/>\n$Hotfix = Get-Hotfix | Where {$_.HotFixid -eq &quot;KB3146714&quot;}<br \/>\n# If the $Hotfix variable is empty, no hotfix is installed, then install the hotfix<br \/>\nIf ($Hotfix -eq $null) {<br \/>\n# Set value of command to run to install the KB38146714 hotfix<br \/>\n[String]$Expression = &quot;wusa.exe .\\Windows8-RT-KB3146714-x64.msu \/Quiet \/NoRestart&quot;<br \/>\n# Runs the install process<br \/>\nInvoke-Expression $expression<br \/>\n}<br \/>\n} # End HotfixCheck Function<br \/>\n[\/sourcecode]<br \/>\nAs you can see, comments are an easy add to your PowerShell script and can serve many purposes. We write about this in our Exchange 2016 and Exchange Online books, so visit our shop to pick up your own copy for reference today.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Writing a script can be hard, making it reusable a bit harder and having someone else understand it&#8217;s purpose one of the hardest things you can do. To make your life and their life easier, the use of Comments is an easy way to enhance or augment a script. Below are a few examples of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rop_custom_images_group":[],"rop_custom_messages_group":[],"rop_publish_now":"initial","rop_publish_now_accounts":[],"rop_publish_now_history":[],"rop_publish_now_status":"pending","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-586","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>No Comment(ing)? Not in PowerShell - Practical PowerShell<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/practicalpowershell.com\/no-commenting-not-in-powershell\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"No Comment(ing)? Not in PowerShell - Practical PowerShell\" \/>\n<meta property=\"og:description\" content=\"Writing a script can be hard, making it reusable a bit harder and having someone else understand it&#8217;s purpose one of the hardest things you can do. To make your life and their life easier, the use of Comments is an easy way to enhance or augment a script. Below are a few examples of [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/practicalpowershell.com\/no-commenting-not-in-powershell\/\" \/>\n<meta property=\"og:site_name\" content=\"Practical PowerShell\" \/>\n<meta property=\"article:published_time\" content=\"2018-06-11T14:00:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-03-14T22:40:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Comments-150x150.jpg\" \/>\n<meta name=\"author\" content=\"damian\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"damian\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/no-commenting-not-in-powershell\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/no-commenting-not-in-powershell\\\/\"},\"author\":{\"name\":\"damian\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#\\\/schema\\\/person\\\/4d0733c81966e744aabbb49f56d64deb\"},\"headline\":\"No Comment(ing)? Not in PowerShell\",\"datePublished\":\"2018-06-11T14:00:27+00:00\",\"dateModified\":\"2020-03-14T22:40:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/no-commenting-not-in-powershell\\\/\"},\"wordCount\":401,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#\\\/schema\\\/person\\\/4d0733c81966e744aabbb49f56d64deb\"},\"image\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/no-commenting-not-in-powershell\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/practicalpowershell.com\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/Comments-150x150.jpg\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/practicalpowershell.com\\\/no-commenting-not-in-powershell\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/no-commenting-not-in-powershell\\\/\",\"url\":\"https:\\\/\\\/practicalpowershell.com\\\/no-commenting-not-in-powershell\\\/\",\"name\":\"No Comment(ing)? Not in PowerShell - Practical PowerShell\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/no-commenting-not-in-powershell\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/no-commenting-not-in-powershell\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/practicalpowershell.com\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/Comments-150x150.jpg\",\"datePublished\":\"2018-06-11T14:00:27+00:00\",\"dateModified\":\"2020-03-14T22:40:28+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/no-commenting-not-in-powershell\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/practicalpowershell.com\\\/no-commenting-not-in-powershell\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/no-commenting-not-in-powershell\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/practicalpowershell.com\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/Comments.jpg?fit=526%2C253&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/practicalpowershell.com\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/Comments.jpg?fit=526%2C253&ssl=1\",\"width\":526,\"height\":253},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/no-commenting-not-in-powershell\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/practicalpowershell.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"No Comment(ing)? Not in PowerShell\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#website\",\"url\":\"https:\\\/\\\/practicalpowershell.com\\\/\",\"name\":\"Practical PowerShell\",\"description\":\"PowerShell books written by experts\",\"publisher\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#\\\/schema\\\/person\\\/4d0733c81966e744aabbb49f56d64deb\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/practicalpowershell.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#\\\/schema\\\/person\\\/4d0733c81966e744aabbb49f56d64deb\",\"name\":\"damian\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g\",\"caption\":\"damian\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"No Comment(ing)? Not in PowerShell - Practical PowerShell","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/practicalpowershell.com\/no-commenting-not-in-powershell\/","og_locale":"en_US","og_type":"article","og_title":"No Comment(ing)? Not in PowerShell - Practical PowerShell","og_description":"Writing a script can be hard, making it reusable a bit harder and having someone else understand it&#8217;s purpose one of the hardest things you can do. To make your life and their life easier, the use of Comments is an easy way to enhance or augment a script. Below are a few examples of [&hellip;]","og_url":"https:\/\/practicalpowershell.com\/no-commenting-not-in-powershell\/","og_site_name":"Practical PowerShell","article_published_time":"2018-06-11T14:00:27+00:00","article_modified_time":"2020-03-14T22:40:28+00:00","og_image":[{"url":"https:\/\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Comments-150x150.jpg","type":"","width":"","height":""}],"author":"damian","twitter_card":"summary_large_image","twitter_misc":{"Written by":"damian","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/practicalpowershell.com\/no-commenting-not-in-powershell\/#article","isPartOf":{"@id":"https:\/\/practicalpowershell.com\/no-commenting-not-in-powershell\/"},"author":{"name":"damian","@id":"https:\/\/practicalpowershell.com\/#\/schema\/person\/4d0733c81966e744aabbb49f56d64deb"},"headline":"No Comment(ing)? Not in PowerShell","datePublished":"2018-06-11T14:00:27+00:00","dateModified":"2020-03-14T22:40:28+00:00","mainEntityOfPage":{"@id":"https:\/\/practicalpowershell.com\/no-commenting-not-in-powershell\/"},"wordCount":401,"commentCount":0,"publisher":{"@id":"https:\/\/practicalpowershell.com\/#\/schema\/person\/4d0733c81966e744aabbb49f56d64deb"},"image":{"@id":"https:\/\/practicalpowershell.com\/no-commenting-not-in-powershell\/#primaryimage"},"thumbnailUrl":"https:\/\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Comments-150x150.jpg","inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/practicalpowershell.com\/no-commenting-not-in-powershell\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/practicalpowershell.com\/no-commenting-not-in-powershell\/","url":"https:\/\/practicalpowershell.com\/no-commenting-not-in-powershell\/","name":"No Comment(ing)? Not in PowerShell - Practical PowerShell","isPartOf":{"@id":"https:\/\/practicalpowershell.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/practicalpowershell.com\/no-commenting-not-in-powershell\/#primaryimage"},"image":{"@id":"https:\/\/practicalpowershell.com\/no-commenting-not-in-powershell\/#primaryimage"},"thumbnailUrl":"https:\/\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Comments-150x150.jpg","datePublished":"2018-06-11T14:00:27+00:00","dateModified":"2020-03-14T22:40:28+00:00","breadcrumb":{"@id":"https:\/\/practicalpowershell.com\/no-commenting-not-in-powershell\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/practicalpowershell.com\/no-commenting-not-in-powershell\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/practicalpowershell.com\/no-commenting-not-in-powershell\/#primaryimage","url":"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Comments.jpg?fit=526%2C253&ssl=1","contentUrl":"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Comments.jpg?fit=526%2C253&ssl=1","width":526,"height":253},{"@type":"BreadcrumbList","@id":"https:\/\/practicalpowershell.com\/no-commenting-not-in-powershell\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/practicalpowershell.com\/"},{"@type":"ListItem","position":2,"name":"No Comment(ing)? Not in PowerShell"}]},{"@type":"WebSite","@id":"https:\/\/practicalpowershell.com\/#website","url":"https:\/\/practicalpowershell.com\/","name":"Practical PowerShell","description":"PowerShell books written by experts","publisher":{"@id":"https:\/\/practicalpowershell.com\/#\/schema\/person\/4d0733c81966e744aabbb49f56d64deb"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/practicalpowershell.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/practicalpowershell.com\/#\/schema\/person\/4d0733c81966e744aabbb49f56d64deb","name":"damian","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g","caption":"damian"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g"}}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/posts\/586","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/comments?post=586"}],"version-history":[{"count":1,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/posts\/586\/revisions"}],"predecessor-version":[{"id":588,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/posts\/586\/revisions\/588"}],"wp:attachment":[{"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/media?parent=586"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/categories?post=586"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/tags?post=586"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}