{"id":83235,"date":"2018-06-29T11:00:54","date_gmt":"2018-06-29T18:00:54","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/?p=83235"},"modified":"2019-02-18T09:09:54","modified_gmt":"2019-02-18T16:09:54","slug":"powertip-determine-your-version-of-powershell-and-host-operating-system","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powertip-determine-your-version-of-powershell-and-host-operating-system\/","title":{"rendered":"PowerTip: Determine your version of PowerShell and host operating system"},"content":{"rendered":"<p><strong>Summary<\/strong>: \u00a0Identify your PowerShell environment by making use of built-in PowerShell variables.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\"><img decoding=\"async\" width=\"34\" height=\"34\" class=\"alignnone size-full wp-image-82735\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" \/><\/a> \u00a0\u00a0 Hey, Scripting Guy! If I\u2019m writing a script, how can I detect if I am running on Windows, Linux, or Mac with PowerShell?<\/p>\n<p style=\"padding-left: 60px\"><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\"><img decoding=\"async\" width=\"34\" height=\"34\" class=\"alignnone size-full wp-image-82745\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" \/><\/a> \u00a0\u00a0 Just use the built-in variable <strong>$PSVersionTable<\/strong>, which has all of the properties you\u2019ll need. Here is an example:<\/p>\n<p style=\"padding-left: 120px\"><strong># Currently operating version<\/strong><\/p>\n<p style=\"padding-left: 120px\"><strong>$PSVersionTable.PSVersion<\/strong><\/p>\n<p style=\"padding-left: 120px\"><strong># Current Host operating System<\/strong><\/p>\n<p style=\"padding-left: 120px\"><strong># If this value is $NULL you are currently running Windows PowerShell 5.x<\/strong><\/p>\n<p style=\"padding-left: 120px\"><strong># else it returns the host environment from the open Source release<\/strong><\/p>\n<p style=\"padding-left: 120px\"><strong>$PSVersionTable.OS<\/strong><\/p>\n<p style=\"padding-left: 60px\"><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/dr_scripto.png\"><img decoding=\"async\" width=\"96\" height=\"145\" class=\"alignnone size-full wp-image-82775\" alt=\"Drawing of Dr. Scripto\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/dr_scripto.png\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Identify your PowerShell environment by making use of built-in PowerShell variables.<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[639],"tags":[56,356,154,45],"class_list":["post-83235","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powertip","tag-guest-blogger","tag-powertip","tag-sean-kearney","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Identify your PowerShell environment by making use of built-in PowerShell variables.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/83235","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=83235"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/83235\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=83235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=83235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=83235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}