{"id":858,"date":"2014-08-05T11:59:00","date_gmt":"2014-08-05T11:59:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/08\/05\/powertip-expand-environmental-variables-with-powershell\/"},"modified":"2014-08-05T11:59:00","modified_gmt":"2014-08-05T11:59:00","slug":"powertip-expand-environmental-variables-with-powershell","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powertip-expand-environmental-variables-with-powershell\/","title":{"rendered":"PowerTip: Expand Environmental Variables with PowerShell"},"content":{"rendered":"<p><b>Summary<\/b>: Learn to expand the value of environmental variables by using Windows PowerShell.<\/p>\n<p><img decoding=\"async\" alt=\"Hey, Scripting Guy! Question\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" \/>&nbsp;How can I use Windows PowerShell to find the value of a common environmental variable <br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;such as&nbsp;<b>%username%<\/b>&nbsp;or&nbsp;<b>%computername%<\/b>?<\/p>\n<p style=\"margin-left:30px\"><img decoding=\"async\" alt=\"Hey, Scripting Guy! Answer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" \/>&nbsp;Use the&nbsp;<b>ExpandEnvornmentalVariables<\/b>&nbsp;static method from the<br \/><b>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.Environment<\/b>&nbsp;.NET Framework class, for example:<\/p>\n<p style=\"margin-left:90px\">[System.Environment]::ExpandEnvironmentVariables(&quot;%username%&quot;)<\/p>\n<p style=\"margin-left:90px\">[System.Environment]::ExpandEnvironmentVariables(&quot;%computername%&quot;)<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7610.Dr.ScriptoForTips.jpg\"><img decoding=\"async\" alt=\" \" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7610.Dr.ScriptoForTips.jpg\" border=\"0\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn to expand the value of environmental variables by using Windows PowerShell. &nbsp;How can I use Windows PowerShell to find the value of a common environmental variable &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;such as&nbsp;%username%&nbsp;or&nbsp;%computername%? &nbsp;Use the&nbsp;ExpandEnvornmentalVariables&nbsp;static method from the&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.Environment&nbsp;.NET Framework class, for example: [System.Environment]::ExpandEnvironmentVariables(&quot;%username%&quot;) [System.Environment]::ExpandEnvironmentVariables(&quot;%computername%&quot;)<\/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":[1],"tags":[356,3,45],"class_list":["post-858","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-powertip","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Learn to expand the value of environmental variables by using Windows PowerShell. &nbsp;How can I use Windows PowerShell to find the value of a common environmental variable &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;such as&nbsp;%username%&nbsp;or&nbsp;%computername%? &nbsp;Use the&nbsp;ExpandEnvornmentalVariables&nbsp;static method from the&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.Environment&nbsp;.NET Framework class, for example: [System.Environment]::ExpandEnvironmentVariables(&quot;%username%&quot;) [System.Environment]::ExpandEnvironmentVariables(&quot;%computername%&quot;)<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/858","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=858"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/858\/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=858"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=858"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=858"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}