August 5th, 2014

PowerTip: Expand Environmental Variables with PowerShell

Doctor Scripto
Scripter

Summary: Learn to expand the value of environmental variables by using Windows PowerShell.

Hey, Scripting Guy! Question How can I use Windows PowerShell to find the value of a common environmental variable
           such as %username% or %computername%?

Hey, Scripting Guy! Answer Use the ExpandEnvornmentalVariables static method from the
           System.Environment .NET Framework class, for example:

[System.Environment]::ExpandEnvironmentVariables("%username%")

[System.Environment]::ExpandEnvironmentVariables("%computername%")

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.