{"id":9198,"date":"2023-01-11T09:28:12","date_gmt":"2023-01-11T14:28:12","guid":{"rendered":"https:\/\/jdhitsolutions.com\/blog\/?p=9198"},"modified":"2023-01-11T09:28:16","modified_gmt":"2023-01-11T14:28:16","slug":"best-practices-make-perfect","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9198\/best-practices-make-perfect\/","title":{"rendered":"Best Practices Make Perfect"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\" id=\"best-practices-make-perfect\"><\/h1>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>This post is a reprint from an article published to my premium PowerShell newsletter <em>Behind the PowerShell Pipeline<\/em> available on <a href=\"https:\/\/jeffhicks.substack.com\" target=\"_blank\" rel=\"noreferrer noopener\">Substack<\/a>. Subscribers receive 6-8 articles like this a month delivered to their inbox or available on the Substack app. I hope you'll consider subscribing. Trial subscriptions are available.<\/p>\n<\/blockquote>\n\n\n\n<p>Over the course of the last several weeks, I've been sharing and demonstrating techniques for writing effective PowerShell functions. I know I've mentioned a few recommended best practices. But since they are important, I want to review and re-emphasize them. These practices will make your code easier to write, easier to debug or troubleshoot, and more secure. I'd like to think some of them are simple, common sense, but sometimes we need someone to remind us. These items are not in any particular order.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"follow-naming-conventions\">Follow Naming Conventions<\/h2>\n\n\n\n<p>Give your functions a meaningful name using the Verb-Noun naming convention. You can give a .ps1 script file any name you want that works for you, but functions should follow the Verb-Noun naming convention. If I can't find the verb portion of your function by running Get-Verb, you've done something wrong. I understand it can sometimes be tricky to find the right verb. But find something as close as possible. You can always create an alias for your function using any verb you wish.<\/p>\n\n\n\n<p>The noun should be singular, although I've been known to bend that rule from time to time. Make the noun meaningful and specific. If there is the possibility of a naming collision, consider adding a prefix to the noun. The prefix could be your initials or maybe an organization abbreviation. The prefix should eliminate naming collisions and make identifying your commands easier.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>If you have a naming collision, you can run a command using its fully qualified name: <\/p>\n\n\n\n<p>  <code>smbshare\\get-smbshare <\/code> <\/p>\n\n\n\n<p>Specify the command's module name with the command name.<\/p>\n<\/blockquote>\n\n\n\n<p>The other critical naming convention is to avoid aliases in your scripts. Feel free to use aliases as much as you want when running PowerShell interactively at a console prompt. But in scripts, use full cmdlet names and parameter names. I would suggest even using parameter names for positional parameters. If you use an editor like VS Code that has Intellisense, it isn't that much of a burden. You only have to write your code once, so write it the right way the first time. <\/p>\n\n\n\n<p>That said, feel free to write your function in VSCode using all the aliases you want. When you are finished, use VSCode to expand your aliases. You can use the command from the command palette or the keyboard shortcut.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/01\/expand-alias.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"195\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/01\/expand-alias-1024x195.png\" alt=\"expand alias in VS Code\" class=\"wp-image-9200\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/01\/expand-alias-1024x195.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/01\/expand-alias-300x57.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/01\/expand-alias-768x147.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/01\/expand-alias-850x162.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/01\/expand-alias.png 1515w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>Note that this will <strong>not <\/strong>add missing parameter names.<\/p>\n\n\n\n<p>Because of the way PowerShell commands are designed, it is practically self-documenting if you use full command and parameter names.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"no-passwords\">No Passwords<\/h2>\n\n\n\n<p>I'd like to think this is a given, but if you need a reminder, do not hard code any passwords or credentials into your scripts and functions. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$pw = \"Open$esame!\"\n...\nfoo.exe \/u administrator \/p $pw<\/code><\/pre>\n\n\n\n<p>And also, avoid this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Param(\n[string]$Name,\n[string]$Password\n)<\/code><\/pre>\n\n\n\n<p>If your command needs a password, have the user enter a PSCredential.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Param(\n [pscredential]$Credential\n)<\/code><\/pre>\n\n\n\n<p>This doesn't mean the credential object needs to be created ahead of time. The user can specify the username, and PowerShell will prompt for the password.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Another option is to integrate Microsoft's SecretStore and SecretManagement modules.<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"be-agnostic\">Be Agnostic<\/h2>\n\n\n\n<p>Your PowerShell code should be agnostic. By that, I mean it should not have hard-coded values for things like a domain name. This is bad form.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$domain = \"ContosoCorp.pri\"<\/code><\/pre>\n\n\n\n<p>At the very least, use PowerShell to populate the value.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$domain = (Get-ADDomain).DNSRoot<\/code><\/pre>\n\n\n\n<p>You could also make this a parameter and let the user specify a value. Or, and this is an advanced technique, write your function to use configuration data from a .psd1 file.<\/p>\n\n\n\n<p><em>If you can't show me your code without having to sanitize it first, I would say you are doing something wrong<\/em>. It may feel like you are saving time, but I would argue it is actually making your code less secure.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"comments-count\">Comments Count<\/h2>\n\n\n\n<p>We always talk about the need for internal documentation. Reading PowerShell code should be like reading a story. You should be able to follow the action. If you use full cmdlet and parameter names, that handles the majority of the work. If you include meaningful Write-Verbose messages, that too will fill in the gaps. You only need to add comment sections when running a block of .NET code that might be difficult to understand or for sections of your script that need an explanation about why you are using the code you are. As your code matures and you update it, inserting a comment with a critical change can be helpful.<\/p>\n\n\n\n<p>Code comments are as much for you as the next person. You may be the one looking at code six months later, struggling to figure out what you were trying to achieve.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"make-it-pretty\">Make It Pretty<\/h2>\n\n\n\n<p>I remember back in my VBScript days. A forum member was having problems with his code. I offered to help, and he posted his code. It was hundreds of lines of single-spaced, left-justified code. It was impossible to read, and VBScript was hard enough. Indentation and white space matters. I just mentioned that your code should tell a story. How your code is displayed in a file can help tell that story. There is no performance penalty for blank lines or white space. If your code is easier to read, it is easier to debug and troubleshoot. <\/p>\n\n\n\n<p>The easiest way to do this is to write your function in VS Code. Right-click on the editor pane, select \"Format Document\" or use the keyboard shortcut.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/01\/format-document.png\"><img loading=\"lazy\" decoding=\"async\" width=\"741\" height=\"937\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/01\/format-document.png\" alt=\"format document in VS Code\" class=\"wp-image-9201\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/01\/format-document.png 741w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/01\/format-document-237x300.png 237w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/01\/format-document-300x379.png 300w\" sizes=\"auto, (max-width: 741px) 100vw, 741px\" \/><\/a><\/figure>\n\n\n\n<p>The first time I saw this in action, it felt like magic and was the thing that pushed me into the arms of VS Code. You can also configure VSCode to format the file every time you save it.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/01\/format-on-save.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"308\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/01\/format-on-save-1024x308.png\" alt=\"format on save in VS Code\" class=\"wp-image-9202\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/01\/format-on-save-1024x308.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/01\/format-on-save-300x90.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/01\/format-on-save-768x231.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/01\/format-on-save-1536x461.png 1536w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/01\/format-on-save-2048x615.png 2048w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/01\/format-on-save-850x255.png 850w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<p>I hope that many of you are already following these recommendations. If not, I\u2019d like to know why. You can leave a comment on this article. Perhaps I can clarify or provide additional context. Finding the code to use in your PowerShell scripting project is only part of the job. How you use the code is equally important.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post is a reprint from an article published to my premium PowerShell newsletter Behind the PowerShell Pipeline available on Substack. Subscribers receive 6-8 articles like this a month delivered to their inbox or available on the Substack app. I hope you&#8217;ll consider subscribing. Trial subscriptions are available. Over the course of the last several&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"New on the blog: Best Practices Make Perfect #PowerShell","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[60,4],"tags":[534,540,662],"class_list":["post-9198","post","type-post","status-publish","format-standard","hentry","category-best-practices","category-powershell","tag-powershell","tag-scripting","tag-substack"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Best Practices Make Perfect &#8226; The Lonely Administrator<\/title>\n<meta name=\"description\" content=\"A set of recommended PowerShell scripting best practices reprinted from the Behind the PowerShell Pipeline newsletter published on Substack.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/9198\/best-practices-make-perfect\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Best Practices Make Perfect &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"A set of recommended PowerShell scripting best practices reprinted from the Behind the PowerShell Pipeline newsletter published on Substack.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/9198\/best-practices-make-perfect\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2023-01-11T14:28:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-11T14:28:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/01\/expand-alias-1024x195.png\" \/>\n<meta name=\"author\" content=\"Jeffery Hicks\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:site\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeffery Hicks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9198\\\/best-practices-make-perfect\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9198\\\/best-practices-make-perfect\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Best Practices Make Perfect\",\"datePublished\":\"2023-01-11T14:28:12+00:00\",\"dateModified\":\"2023-01-11T14:28:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9198\\\/best-practices-make-perfect\\\/\"},\"wordCount\":1039,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9198\\\/best-practices-make-perfect\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/01\\\/expand-alias-1024x195.png\",\"keywords\":[\"PowerShell\",\"Scripting\",\"substack\"],\"articleSection\":[\"Best Practices\",\"PowerShell\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9198\\\/best-practices-make-perfect\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9198\\\/best-practices-make-perfect\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9198\\\/best-practices-make-perfect\\\/\",\"name\":\"Best Practices Make Perfect &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9198\\\/best-practices-make-perfect\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9198\\\/best-practices-make-perfect\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/01\\\/expand-alias-1024x195.png\",\"datePublished\":\"2023-01-11T14:28:12+00:00\",\"dateModified\":\"2023-01-11T14:28:16+00:00\",\"description\":\"A set of recommended PowerShell scripting best practices reprinted from the Behind the PowerShell Pipeline newsletter published on Substack.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9198\\\/best-practices-make-perfect\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9198\\\/best-practices-make-perfect\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9198\\\/best-practices-make-perfect\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/01\\\/expand-alias.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/01\\\/expand-alias.png\",\"width\":1515,\"height\":289},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9198\\\/best-practices-make-perfect\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Best Practices Make Perfect\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/\",\"name\":\"The Lonely Administrator\",\"description\":\"Practical Advice for the Automating IT Pro\",\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\",\"name\":\"Jeffery Hicks\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"caption\":\"Jeffery Hicks\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Best Practices Make Perfect &#8226; The Lonely Administrator","description":"A set of recommended PowerShell scripting best practices reprinted from the Behind the PowerShell Pipeline newsletter published on Substack.","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:\/\/jdhitsolutions.com\/blog\/powershell\/9198\/best-practices-make-perfect\/","og_locale":"en_US","og_type":"article","og_title":"Best Practices Make Perfect &#8226; The Lonely Administrator","og_description":"A set of recommended PowerShell scripting best practices reprinted from the Behind the PowerShell Pipeline newsletter published on Substack.","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9198\/best-practices-make-perfect\/","og_site_name":"The Lonely Administrator","article_published_time":"2023-01-11T14:28:12+00:00","article_modified_time":"2023-01-11T14:28:16+00:00","og_image":[{"url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/01\/expand-alias-1024x195.png","type":"","width":"","height":""}],"author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9198\/best-practices-make-perfect\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9198\/best-practices-make-perfect\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Best Practices Make Perfect","datePublished":"2023-01-11T14:28:12+00:00","dateModified":"2023-01-11T14:28:16+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9198\/best-practices-make-perfect\/"},"wordCount":1039,"commentCount":0,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9198\/best-practices-make-perfect\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/01\/expand-alias-1024x195.png","keywords":["PowerShell","Scripting","substack"],"articleSection":["Best Practices","PowerShell"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/9198\/best-practices-make-perfect\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9198\/best-practices-make-perfect\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9198\/best-practices-make-perfect\/","name":"Best Practices Make Perfect &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9198\/best-practices-make-perfect\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9198\/best-practices-make-perfect\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/01\/expand-alias-1024x195.png","datePublished":"2023-01-11T14:28:12+00:00","dateModified":"2023-01-11T14:28:16+00:00","description":"A set of recommended PowerShell scripting best practices reprinted from the Behind the PowerShell Pipeline newsletter published on Substack.","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9198\/best-practices-make-perfect\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/9198\/best-practices-make-perfect\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9198\/best-practices-make-perfect\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/01\/expand-alias.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/01\/expand-alias.png","width":1515,"height":289},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9198\/best-practices-make-perfect\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"Best Practices Make Perfect"}]},{"@type":"WebSite","@id":"https:\/\/jdhitsolutions.com\/blog\/#website","url":"https:\/\/jdhitsolutions.com\/blog\/","name":"The Lonely Administrator","description":"Practical Advice for the Automating IT Pro","publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jdhitsolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9","name":"Jeffery Hicks","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","caption":"Jeffery Hicks"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":8808,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8808\/behind-the-powershell-pipeline\/","url_meta":{"origin":9198,"position":0},"title":"Behind the PowerShell Pipeline","author":"Jeffery Hicks","date":"January 19, 2022","format":false,"excerpt":"Last week I made some passing references on Twitter to a new project I am working on this year. I thought I'd take a little time to explain it and hopefully entice a few of you into joining me. I've been blogging here for about ten years, if not longer.\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"behind the pipeline","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/behind.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":9225,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9225\/automation-decisions\/","url_meta":{"origin":9198,"position":1},"title":"Automation Decisions","author":"Jeffery Hicks","date":"February 28, 2023","format":false,"excerpt":"This post is an updated reprint from an article published to my premium PowerShell newsletter Behind the PowerShell Pipeline available on Substack. Subscribers receive 6-8 articles like this a month delivered to their inbox or available on the Substack app. I hope you\u2019ll consider subscribing. Trial subscriptions are available. I\u2019ve\u2026","rel":"","context":"In &quot;Best Practices&quot;","block_context":{"text":"Best Practices","link":"https:\/\/jdhitsolutions.com\/blog\/category\/best-practices\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1036,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1036\/join-me-in-orlando\/","url_meta":{"origin":9198,"position":2},"title":"Join Me in Orlando","author":"Jeffery Hicks","date":"December 30, 2010","format":false,"excerpt":"I will be presenting 3 sessions at Techmentor Orlando 2011. The conference runs March 14-18, 2011 at the Disney Yacht Club. My sessions are all on Wednesday March 16. In addition to all the other fabulous material at the conference I will be presenting the following: PowerShell Scripting Best Practices\u2026","rel":"","context":"In &quot;Active Directory&quot;","block_context":{"text":"Active Directory","link":"https:\/\/jdhitsolutions.com\/blog\/category\/active-directory\/"},"img":{"alt_text":"Disney Yacht Club","src":"https:\/\/i0.wp.com\/techmentorevents.com\/design\/ecg\/techmentorevents\/home\/img\/portal_2011spring.gif?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":672,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/672\/teched-2010-demos\/","url_meta":{"origin":9198,"position":3},"title":"TechEd 2010 Demos","author":"Jeffery Hicks","date":"June 10, 2010","format":false,"excerpt":"As promised,\u00a0 I've assembled my demo scripts as well as the transcriptfrom my TechEd 2010 talk Paradigm Shift Microsoft Visual Basic Scripting Edition to Windows PowerShell. The official slide deck is supposed to be available on the TechEd web site.\u00a0 I'm going to post an expanded version of the deck\u2026","rel":"","context":"In &quot;Best Practices&quot;","block_context":{"text":"Best Practices","link":"https:\/\/jdhitsolutions.com\/blog\/category\/best-practices\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4966,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4966\/powershell-toolmaking-dos-and-donts\/","url_meta":{"origin":9198,"position":4},"title":"PowerShell Toolmaking Dos and Don&#8217;ts","author":"Jeffery Hicks","date":"May 2, 2016","format":false,"excerpt":"During the last Microsoft MVP Summit, Channel 9 invited MVPs into their studios to record short presentations on anything they wanted. This was too good a deal to pass on, so my friend Greg Shields and I jumped into the studio to talk about PowerShell Toolmaking. To be more accurate,\u2026","rel":"","context":"In &quot;MVP&quot;","block_context":{"text":"MVP","link":"https:\/\/jdhitsolutions.com\/blog\/category\/mvp\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":582,"url":"https:\/\/jdhitsolutions.com\/blog\/writing\/582\/powershell-in-the-enterprise\/","url_meta":{"origin":9198,"position":5},"title":"PowerShell in the Enterprise","author":"Jeffery Hicks","date":"March 4, 2010","format":false,"excerpt":"A new whitepaper I wrote for Quest Software has finally made it's public appearance: PowerShell in the Enterprise: Best Practices and Recommendations. The paper discusses some best practices for using PowerShell in an enterprise environment. Essentially, getting the most from your PowerShell \"investment\", especially when you might have multiple PowerShell-based\u2026","rel":"","context":"In &quot;Best Practices&quot;","block_context":{"text":"Best Practices","link":"https:\/\/jdhitsolutions.com\/blog\/category\/best-practices\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/9198","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=9198"}],"version-history":[{"count":2,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/9198\/revisions"}],"predecessor-version":[{"id":9203,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/9198\/revisions\/9203"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=9198"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=9198"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=9198"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}