{"id":7361,"date":"2020-03-13T10:58:12","date_gmt":"2020-03-13T14:58:12","guid":{"rendered":"https:\/\/jdhitsolutions.com\/blog\/?p=7361"},"modified":"2020-03-13T10:58:12","modified_gmt":"2020-03-13T14:58:12","slug":"powershell-7-cross-platform-scripting-tips-and-traps","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7361\/powershell-7-cross-platform-scripting-tips-and-traps\/","title":{"rendered":"PowerShell 7 Cross-Platform Scripting Tips and Traps"},"content":{"rendered":"<p>One of the reasons you want to adopt PowerShell 7 on your desktop, is that it can\u00a0 be used cross-platform. Theoretically, you can write a PowerShell script or function that works on Windows, Linux, and Mac. However, this is not without challenges. In some ways, it feels like we are back to the early days of PowerShell scripting where we are all trying to figure out what to do. Based on my experiences, let me share some thoughts on what I think you should keep in mind.<\/p>\n<p>Remember, I am focusing on PowerShell code you will write in script files and modules. Using PowerShell interactively and cross-platform has its own set of rules. Although let me add that the more experience you have working interactively cross-platform, the easier it will be to write cross-platform code.<\/p>\n<h2>No Aliases<\/h2>\n<p>A long established community best practice in PowerShell scripting is not using command and parameter aliases. In a cross-platform world, this is even more critical. You may have been in the habit of using <em>Sort<\/em> in your code in place of <em>Sort-Object<\/em>. I know I have. I didn't mind bending the no alias rule abit because there was nothing cryptic about <em>Sort<\/em>.<\/p>\n<p>But in the Linux world, <em>sort<\/em> is a native command. There is no PowerShell alias. If your code uses <em>sort<\/em>, on Linux it will call the native command which will most likely break your code.<\/p>\n<p>You need to get in the habit now of using full cmdlet and parameter names. In Visual Studio Code with the PowerShell extension, it is very easy to convert all aliases. In the command palette use PowerShell: Expand Alias or the keyboard shortcut <em>Shift+Alt+E<\/em>.<\/p>\n<h2>No CIM<\/h2>\n<p>Another key thing to watch for is the lack of WMI and CIM on non-Windows platforms. This probably doesn't come as much of a surprise. CIM support is part of the Windows Management Framework. The name gives it away. Any script that is using a CIM cmdlet will fail on a non-Windows system. This also includes commands like Get-Volume, that are using CIM under the hood. If the command you are using has a <em>-CimSession<\/em> parameter, it won't work cross-platform.<\/p>\n<h2>Testing for Version and Edition<\/h2>\n<p>What this means is that you will need to include additional error handling in your commands. You will need to check items like <em>$PSVersionTable<\/em>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7363\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-1.png\" alt=\"hicks-scripting-1\" width=\"1881\" height=\"628\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-1.png 1881w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-1-300x100.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-1-1024x342.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-1-768x256.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-1-1536x513.png 1536w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-1-850x284.png 850w\" sizes=\"auto, (max-width: 1881px) 100vw, 1881px\" \/><\/p>\n<p>Here's what I have for PowerShell 7 on Windows.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7364\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-2.png\" alt=\"hicks-scripting-2\" width=\"814\" height=\"376\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-2.png 814w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-2-300x139.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-2-768x355.png 768w\" sizes=\"auto, (max-width: 814px) 100vw, 814px\" \/><\/p>\n<p>And Windows PowerShell.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7365\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-3.png\" alt=\"hicks-scripting-3\" width=\"958\" height=\"466\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-3.png 958w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-3-300x146.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-3-768x374.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-3-850x413.png 850w\" sizes=\"auto, (max-width: 958px) 100vw, 958px\" \/><\/p>\n<p>By the way, you can use <em>$PSEdition<\/em> on PowerShell 7 and Windows PowerShell to get the same value you see here.<\/p>\n<p>In addition to testing values from <em>$PSVersionTable<\/em>, there are a number of new variables that might come in handy.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7366\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-4.png\" alt=\"hicks-scripting-4\" width=\"723\" height=\"378\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-4.png 723w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-4-300x157.png 300w\" sizes=\"auto, (max-width: 723px) 100vw, 723px\" \/><\/p>\n<p>These variables do not exist in Windows PowerShell. Here's one way you might use them.<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">if ($psedition -eq 'core' -AND $IsWindows) {\n \"PS7 on Windows\"\n}\nelseif ($psedition -eq 'core' -AND (-Not $IsWindows) ) {\n \"PS7 on Linux OR MacOS\"\n}\nelseif ($PSEdition -eq \"Desktop\" -AND ($psversiontable.PSVersion.Major -eq 5 -AND $psversiontable.PSVersion.Minor -eq 1)) {\n \"Must be Windows PowerShell 5.1\"\n}\nelse {\n   \"All other Windows PowerShell versions\"\n}\n<\/pre>\n<p>Testing is important and can be tricky. For example, even though you don't have Get-Ciminstance in PowerShell 7 on Linux, you do on Windows. You will need to be familiar with Get-Command and Get-Module and be able to run them on non-Windows platforms.<br \/>\nHere's a code snippet you might use to validate a requirement for your code.<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">Try {\n    Get-Command -name Get-Volume -erroraction stop\n} \nCatch {\n    Write-Warning \"Command not available on this system.\"\n    #bail out of the command\n    return\n}\n<\/pre>\n<p>If you've ignored learning how to properly use <em>Try\/Catch<\/em>, now would be a good time. Another option you might consider adding is the use of Dynamic Parameters. This is a complex topic that I don't want to get into here. But you could define some parameters of your command dynamically, depending on the PowerShell flavor.<\/p>\n<h2>Require Minimal Versions<\/h2>\n<p>If you are writing stand-alone scripts that might be run on different PowerShell versions, you need to insert a <em>#requires<\/em> statement at the beginning of your script.<\/p>\n<pre class=\"lang:ps mark:0 decode:true\"># requires -version 7.0\n<\/pre>\n<p>This is very important if you are using any of the new features in PowerShell 7 such as the new parallel parameter with <em>ForEach-Object<\/em>. Read the <em>about_requires<\/em> help topic for more detail.<\/p>\n<h2>Scripting with Remoting<\/h2>\n<p>The scripting element you might incorporate is PowerShell remoting. I often use this feature to make my command easily scale. What you have to take into account is how your command will be used with remote machines. You might need to define separate parameter sets with clear documentation that one set is used for Windows machines and another set for Linux. Or Windows PowerShell vs PowerShell 7.<\/p>\n<p>I love that PowerShell 7 remoting can now use <em>ssh<\/em>. If you enable and configure it on your remote machines, you can then use <em>ssh<\/em> remoting in your code. Or, if you will have a mix of remote machines, perhaps you write your code to only accept PSSessions. The user of your code would be responsible for creating PSSessions. Some sessions could use WinRM and some could be using SSH. Your command can be designed to take an array of PSSessions from the pipeline and internally you could pass them to Invoke-Command. Of course, you still need to take other error handling, validation and testing into account. But this could be a simple way to manage multiple remote systems, regardless of whether they are running Windows or Linux.<\/p>\n<h2>Your Plan<\/h2>\n<p>What does all of this mean for you? First, I'd say you need to become comfortable with PowerShell 7 and all the new features it brings to the party.\u00a0 Assuming you are going to be running PowerShell 7 on your desktop, you can begin testing if the code still works. I have yet to find any scripts or functions that I wrote for Windows PowerShell fail to run locally under PowerShell 7.<\/p>\n<p>Assuming you have a need for PowerShell 7 on remote servers, then you can begin assessing what you need to manage and how you will go about it. I always stress to students that you have to think about who is going to run your code. Now, you also have to think about where.<\/p>\n<p>Even if most of your scripting work is for Windows PowerShell, if you begin to pay attention to PowerShell 7 scripting requirements, I think the quality of your code overall will improve.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the reasons you want to adopt PowerShell 7 on your desktop, is that it can\u00a0 be used cross-platform. Theoretically, you can write a PowerShell script or function that works on Windows, Linux, and Mac. However, this is not without challenges. In some ways, it feels like we are back to the early days&#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: #PowerShell 7 Cross-Platform Scripting Tips and Traps  #PSBlogWeek #PS7Now","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[610,8],"tags":[534,624,490,540],"class_list":["post-7361","post","type-post","status-publish","format-standard","hentry","category-powershell-7","category-scripting","tag-powershell","tag-ps7now","tag-psblogweek","tag-scripting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PowerShell 7 Cross-Platform Scripting Tips and Traps &#8226; The Lonely Administrator<\/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:\/\/jdhitsolutions.com\/blog\/scripting\/7361\/powershell-7-cross-platform-scripting-tips-and-traps\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PowerShell 7 Cross-Platform Scripting Tips and Traps &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"One of the reasons you want to adopt PowerShell 7 on your desktop, is that it can\u00a0 be used cross-platform. Theoretically, you can write a PowerShell script or function that works on Windows, Linux, and Mac. However, this is not without challenges. In some ways, it feels like we are back to the early days...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/scripting\/7361\/powershell-7-cross-platform-scripting-tips-and-traps\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2020-03-13T14:58:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-1.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=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/7361\\\/powershell-7-cross-platform-scripting-tips-and-traps\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/7361\\\/powershell-7-cross-platform-scripting-tips-and-traps\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"PowerShell 7 Cross-Platform Scripting Tips and Traps\",\"datePublished\":\"2020-03-13T14:58:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/7361\\\/powershell-7-cross-platform-scripting-tips-and-traps\\\/\"},\"wordCount\":996,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/7361\\\/powershell-7-cross-platform-scripting-tips-and-traps\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/hicks-scripting-1.png\",\"keywords\":[\"PowerShell\",\"PS7Now\",\"PSBlogWeek\",\"Scripting\"],\"articleSection\":[\"PowerShell 7\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/7361\\\/powershell-7-cross-platform-scripting-tips-and-traps\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/7361\\\/powershell-7-cross-platform-scripting-tips-and-traps\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/7361\\\/powershell-7-cross-platform-scripting-tips-and-traps\\\/\",\"name\":\"PowerShell 7 Cross-Platform Scripting Tips and Traps &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/7361\\\/powershell-7-cross-platform-scripting-tips-and-traps\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/7361\\\/powershell-7-cross-platform-scripting-tips-and-traps\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/hicks-scripting-1.png\",\"datePublished\":\"2020-03-13T14:58:12+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/7361\\\/powershell-7-cross-platform-scripting-tips-and-traps\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/7361\\\/powershell-7-cross-platform-scripting-tips-and-traps\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/7361\\\/powershell-7-cross-platform-scripting-tips-and-traps\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/hicks-scripting-1.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/hicks-scripting-1.png\",\"width\":1881,\"height\":628},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/7361\\\/powershell-7-cross-platform-scripting-tips-and-traps\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell 7\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell-7\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PowerShell 7 Cross-Platform Scripting Tips and Traps\"}]},{\"@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":"PowerShell 7 Cross-Platform Scripting Tips and Traps &#8226; The Lonely Administrator","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\/scripting\/7361\/powershell-7-cross-platform-scripting-tips-and-traps\/","og_locale":"en_US","og_type":"article","og_title":"PowerShell 7 Cross-Platform Scripting Tips and Traps &#8226; The Lonely Administrator","og_description":"One of the reasons you want to adopt PowerShell 7 on your desktop, is that it can\u00a0 be used cross-platform. Theoretically, you can write a PowerShell script or function that works on Windows, Linux, and Mac. However, this is not without challenges. In some ways, it feels like we are back to the early days...","og_url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7361\/powershell-7-cross-platform-scripting-tips-and-traps\/","og_site_name":"The Lonely Administrator","article_published_time":"2020-03-13T14:58:12+00:00","og_image":[{"url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-1.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":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7361\/powershell-7-cross-platform-scripting-tips-and-traps\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7361\/powershell-7-cross-platform-scripting-tips-and-traps\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"PowerShell 7 Cross-Platform Scripting Tips and Traps","datePublished":"2020-03-13T14:58:12+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7361\/powershell-7-cross-platform-scripting-tips-and-traps\/"},"wordCount":996,"commentCount":3,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7361\/powershell-7-cross-platform-scripting-tips-and-traps\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-1.png","keywords":["PowerShell","PS7Now","PSBlogWeek","Scripting"],"articleSection":["PowerShell 7","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/7361\/powershell-7-cross-platform-scripting-tips-and-traps\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7361\/powershell-7-cross-platform-scripting-tips-and-traps\/","url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7361\/powershell-7-cross-platform-scripting-tips-and-traps\/","name":"PowerShell 7 Cross-Platform Scripting Tips and Traps &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7361\/powershell-7-cross-platform-scripting-tips-and-traps\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7361\/powershell-7-cross-platform-scripting-tips-and-traps\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-1.png","datePublished":"2020-03-13T14:58:12+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7361\/powershell-7-cross-platform-scripting-tips-and-traps\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/7361\/powershell-7-cross-platform-scripting-tips-and-traps\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7361\/powershell-7-cross-platform-scripting-tips-and-traps\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-1.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-1.png","width":1881,"height":628},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7361\/powershell-7-cross-platform-scripting-tips-and-traps\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell 7","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-7\/"},{"@type":"ListItem","position":2,"name":"PowerShell 7 Cross-Platform Scripting Tips and Traps"}]},{"@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":6142,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6142\/join-me-for-a-2-day-powershell-scripting-workshop\/","url_meta":{"origin":7361,"position":0},"title":"Join Me for a 2 Day PowerShell Scripting Workshop","author":"Jeffery Hicks","date":"November 12, 2018","format":false,"excerpt":"I am very happy to announce a 2 day public PowerShell learning event. In association with the fine people behind the Techmentor conference, I will be presenting a 2 day PowerShell Scripting workshop in Dallas, TX on February 4-5, 2019. There is an option to attend virtually, but you'll really\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"announcer-blue","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/11\/announcer-blue_thumb.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":3722,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3722\/reflections-on-the-powershell-scripting-games\/","url_meta":{"origin":7361,"position":1},"title":"Reflections on the PowerShell Scripting Games","author":"Jeffery Hicks","date":"February 26, 2014","format":false,"excerpt":"During the most recent PowerShell Scripting Games, I was fortunate enough to be one of the judges. Now that the games have concluded I thought I'd share my reflections on the entries. Naturally these are merely my opinions but they are drawn from years of experience with PowerShell and almost\u2026","rel":"","context":"In &quot;Best Practices&quot;","block_context":{"text":"Best Practices","link":"https:\/\/jdhitsolutions.com\/blog\/category\/best-practices\/"},"img":{"alt_text":"talkbubble","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/10\/talkbubble.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":6855,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell-7\/6855\/powershell-scripting-for-linux-is-still-about-the-objects\/","url_meta":{"origin":7361,"position":2},"title":"PowerShell Scripting for Linux is Still About the Objects","author":"Jeffery Hicks","date":"October 8, 2019","format":false,"excerpt":"I've been trying to increase my Linux skills, especially as I begin to write PowerShell scripts and tools that can work cross-platform. One very important concept I want to make sure you don't overlook is that even when scripting for non-Windows platforms, you must still be thinking about objects. The\u2026","rel":"","context":"In &quot;PowerShell 7&quot;","block_context":{"text":"PowerShell 7","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-7\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":6252,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6252\/your-christmas-powershell-prompt\/","url_meta":{"origin":7361,"position":3},"title":"Your Christmas PowerShell Prompt","author":"Jeffery Hicks","date":"December 6, 2018","format":false,"excerpt":"Continuing my fun with PowerShell prompts and because we are in the Christmas season. I\u2019m bringing back my Christmas countdown prompt. I have updated so it should work in both the traditional console and PowerShell ISE. The prompt displays a randomly colorized countdown message with some random decorations. You can\u2026","rel":"","context":"In &quot;Miscellaneous&quot;","block_context":{"text":"Miscellaneous","link":"https:\/\/jdhitsolutions.com\/blog\/category\/miscellaneous\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/12\/image_thumb-2.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/12\/image_thumb-2.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/12\/image_thumb-2.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":6439,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6439\/friday-fun-with-a-cross-platform-powershell-prompt\/","url_meta":{"origin":7361,"position":4},"title":"Friday Fun with a Cross-Platform PowerShell Prompt","author":"Jeffery Hicks","date":"January 18, 2019","format":false,"excerpt":"This year is turning out to be all things cross-platform for me. Continuing this line of discussion I have something fun and simple today. A PowerShell prompt function that will work cross-platform and provide some meaningful information in what I think is a elegant manner. You may not need the\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/image_thumb-20.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/image_thumb-20.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/image_thumb-20.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/image_thumb-20.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":8205,"url":"https:\/\/jdhitsolutions.com\/blog\/books\/8205\/updated-powershell-practice-primer-now-available\/","url_meta":{"origin":7361,"position":5},"title":"Updated PowerShell Practice Primer Now Available","author":"Jeffery Hicks","date":"March 2, 2021","format":false,"excerpt":"I have published a new version of The PowerShell Practice Primer. If you own the book and signed up for notifications, you should have received an email informing you of the new edition. That is a great benefit of publishing on Leanpub. If I update the book, you get the\u2026","rel":"","context":"In &quot;Books&quot;","block_context":{"text":"Books","link":"https:\/\/jdhitsolutions.com\/blog\/category\/books\/"},"img":{"alt_text":"PowerShell Practice Primer","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/03\/cover-thumb.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/7361","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=7361"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/7361\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=7361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=7361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=7361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}