{"id":1697,"date":"2020-06-15T08:00:07","date_gmt":"2020-06-15T14:00:07","guid":{"rendered":"https:\/\/practicalpowershell.com\/?p=1697"},"modified":"2020-06-09T18:40:27","modified_gmt":"2020-06-10T00:40:27","slug":"capitalization-and-scripts","status":"publish","type":"post","link":"https:\/\/practicalpowershell.com\/capitalization-and-scripts\/","title":{"rendered":"Capitalization and Scripts"},"content":{"rendered":"<p>Over time I&#8217;ve learned to write my scripts better.  I try to follow best practices, at least as far as I can allow myself.  One such best practice is capitalization and before we get to far down this rabbit hole, remember that the suggestions below are not required for your script to run and can turn into an OCD issue for others.  Let&#8217; dive in.<\/p>\n<h3>Why Capitalization<\/h3>\n<p>Capitalization makes sentences more readable (and proper format) and in PowerShell capitalization performs the same function (without the requirement).  Readability <\/p>\n<p>Let&#8217;s look at some examples:<\/p>\n<p>Cmdlets (w\/o capitalization)<br \/>\n[sourcecode language=&#8221;powershell&#8221;]<br \/>\nget-complianceretentioneventtype<br \/>\nget-devicecompliancedetailsreportfilter<br \/>\nnew-azurermapplicationgatewaywebapplicationfirewallconfiguration<br \/>\n[\/sourcecode]<\/p>\n<p>Cmdlets (w\/ capitalization<br \/>\n[sourcecode language=&#8221;powershell&#8221;]<br \/>\nGet-ComplianceRetentionEventType<br \/>\nGet-DeviceComplianceDetailsReportFilter<br \/>\nNew-AzureRmApplicationGatewayWebApplicationFirewallConfiguration<br \/>\n[\/sourcecode]<br \/>\nCode sections (w\/o capitalization)<br \/>\n[sourcecode language=&#8221;powershell&#8221;]<br \/>\n$server = $env:computername<br \/>\n    $exchangeproductversion = (gcm exsetup |%{$_.fileversioninfo}).productversion<br \/>\n    if ($exchangeproductversion -like &#039;15.02.*&#039;) {$version = &#039;2019&#039;}<br \/>\n    if ($exchangeproductversion -like &#039;15.01.*&#039;) {$version = &#039;2016&#039;}<br \/>\n    if ($exchangeproductversion -like &#039;15.00.*&#039;) {$version = &#039;2013&#039;}<br \/>\n    if ($exchangeproductversion -lt &#039;15&#039;) {$exit = $true}<br \/>\n    $serverrole = (get-exchangeserver $server).serverrole<br \/>\n    $exinstall = (get-itemproperty hklm:\\software\\microsoft\\exchangeserver\\v15\\setup).msiinstallpath<br \/>\n}<br \/>\n[\/sourcecode]<br \/>\nCode sections (w\/ capitalization)<br \/>\n[sourcecode language=&#8221;powershell&#8221;]<br \/>\n$Server = $env:COMPUTERNAME<br \/>\n    $ExchangeProductVersion = (GCM exsetup |%{$_.Fileversioninfo}).ProductVersion<br \/>\n    If ($ExchangeProductVersion -like &#039;15.02.*&#039;) {$Version = &#039;2019&#039;}<br \/>\n    If ($ExchangeProductVersion -like &#039;15.01.*&#039;) {$Version = &#039;2016&#039;}<br \/>\n    If ($ExchangeProductVersion -like &#039;15.00.*&#039;) {$Version = &#039;2013&#039;}<br \/>\n    If ($ExchangeProductVersion -lt &#039;15&#039;) {$Exit = $True}<br \/>\n    $ServerRole = (Get-ExchangeServer $Server).ServerRole<br \/>\n    $ExInstall = (Get-ItemProperty HKLM:\\SOFTWARE\\Microsoft\\ExchangeServer\\v15\\Setup).MsiInstallPath<br \/>\n}<br \/>\n[\/sourcecode]<br \/>\nNotice that capitalization makes it easier to interpret the cmdlet name of function code.  This speeds up your work with the script (building, troubleshooting and correcting) and\/or helps the next person understand what they script was meant for easier as well. Those long PowerShell cmdlets are profoundly easier to read with correct word capitalization.<\/p>\n<h3>How Far to Take Capitalization<\/h3>\n<p>Since capitalization technically isn&#8217;t required and is considered a best practice only, your use of capitalization should match your needs for the script.  It certainly won&#8217;t make the script run faster or better or any different from a script where capitalization is used infrequently.  As we see from the examples above, it improves the readability of PowerShell code and can assist in assessing what a script does (visual cues).  Do you have to capitalize the first letter of everything in the script?  No, if we were to miss some of the first letters, or just plain forgot to capitalize things, it will just affect the visual cues of the script. <BR><br \/>\nThat being said, practice.  As you&#8217;re typing, capitalize your words. Think about it consciously.  After a line is done, look at it and see if you words are capitalized or if there are things that don&#8217;t look quite right.  Fix them then and there so you do not have to go back to the script or code section again.<BR><br \/>\nPractice.  Again.  It will become second nature eventually.  Trust me, it took a long time to change my frame of mind on this &#8230; and I still slip back to the old method if I am writing a throwaway script.  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Over time I&#8217;ve learned to write my scripts better. I try to follow best practices, at least as far as I can allow myself. One such best practice is capitalization and before we get to far down this rabbit hole, remember that the suggestions below are not required for your script to run and can [&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-1697","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>Capitalization and Scripts - 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\/capitalization-and-scripts\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Capitalization and Scripts - Practical PowerShell\" \/>\n<meta property=\"og:description\" content=\"Over time I&#8217;ve learned to write my scripts better. I try to follow best practices, at least as far as I can allow myself. One such best practice is capitalization and before we get to far down this rabbit hole, remember that the suggestions below are not required for your script to run and can [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/practicalpowershell.com\/capitalization-and-scripts\/\" \/>\n<meta property=\"og:site_name\" content=\"Practical PowerShell\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-15T14:00:07+00:00\" \/>\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\\\/capitalization-and-scripts\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/capitalization-and-scripts\\\/\"},\"author\":{\"name\":\"damian\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#\\\/schema\\\/person\\\/4d0733c81966e744aabbb49f56d64deb\"},\"headline\":\"Capitalization and Scripts\",\"datePublished\":\"2020-06-15T14:00:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/capitalization-and-scripts\\\/\"},\"wordCount\":483,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#\\\/schema\\\/person\\\/4d0733c81966e744aabbb49f56d64deb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/practicalpowershell.com\\\/capitalization-and-scripts\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/capitalization-and-scripts\\\/\",\"url\":\"https:\\\/\\\/practicalpowershell.com\\\/capitalization-and-scripts\\\/\",\"name\":\"Capitalization and Scripts - Practical PowerShell\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#website\"},\"datePublished\":\"2020-06-15T14:00:07+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/capitalization-and-scripts\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/practicalpowershell.com\\\/capitalization-and-scripts\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/capitalization-and-scripts\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/practicalpowershell.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Capitalization and Scripts\"}]},{\"@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":"Capitalization and Scripts - 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\/capitalization-and-scripts\/","og_locale":"en_US","og_type":"article","og_title":"Capitalization and Scripts - Practical PowerShell","og_description":"Over time I&#8217;ve learned to write my scripts better. I try to follow best practices, at least as far as I can allow myself. One such best practice is capitalization and before we get to far down this rabbit hole, remember that the suggestions below are not required for your script to run and can [&hellip;]","og_url":"https:\/\/practicalpowershell.com\/capitalization-and-scripts\/","og_site_name":"Practical PowerShell","article_published_time":"2020-06-15T14:00:07+00:00","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\/capitalization-and-scripts\/#article","isPartOf":{"@id":"https:\/\/practicalpowershell.com\/capitalization-and-scripts\/"},"author":{"name":"damian","@id":"https:\/\/practicalpowershell.com\/#\/schema\/person\/4d0733c81966e744aabbb49f56d64deb"},"headline":"Capitalization and Scripts","datePublished":"2020-06-15T14:00:07+00:00","mainEntityOfPage":{"@id":"https:\/\/practicalpowershell.com\/capitalization-and-scripts\/"},"wordCount":483,"commentCount":0,"publisher":{"@id":"https:\/\/practicalpowershell.com\/#\/schema\/person\/4d0733c81966e744aabbb49f56d64deb"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/practicalpowershell.com\/capitalization-and-scripts\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/practicalpowershell.com\/capitalization-and-scripts\/","url":"https:\/\/practicalpowershell.com\/capitalization-and-scripts\/","name":"Capitalization and Scripts - Practical PowerShell","isPartOf":{"@id":"https:\/\/practicalpowershell.com\/#website"},"datePublished":"2020-06-15T14:00:07+00:00","breadcrumb":{"@id":"https:\/\/practicalpowershell.com\/capitalization-and-scripts\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/practicalpowershell.com\/capitalization-and-scripts\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/practicalpowershell.com\/capitalization-and-scripts\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/practicalpowershell.com\/"},{"@type":"ListItem","position":2,"name":"Capitalization and Scripts"}]},{"@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\/1697","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=1697"}],"version-history":[{"count":3,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/posts\/1697\/revisions"}],"predecessor-version":[{"id":1703,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/posts\/1697\/revisions\/1703"}],"wp:attachment":[{"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/media?parent=1697"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/categories?post=1697"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/tags?post=1697"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}