Skip to content

Resolve Environmental Variable Not Expanding in PowerShell Script on Windows

Vic Phan edited this page Jan 15, 2023 · 1 revision

• The following resolution is for if an environment variable won’t expand in a PowerShell script.
image

• Open the PowerShell script in your desired code editor then go to before you return the variable that contains the environment variable and press the Enter key to create a new space.
image

• Type $< variable > = $ExecutionContext.InvokeCommand.ExpandString($< variable >) to expand the environment variable and save the value in a variable.
image

• Run the PowerShell script again.
image

• The environment variable will expand this time around.
image

Viccy GitHub

Clone this wiki locally