Interpret string with batch-style environment variables in Powershell

484 Views Asked by At

I have a string including environment variables in batch-style notation (%programdata%\App-V) that I need to evaluate in Powershell. Can the %ENV% notation be easily evaluated in Powershell? I am aware that the usual notation for environment variables in Powershell would be $env:ProgramData, but the string is returned to me from another command that I cannot change.

Background information: A Powershell Cmdlet ((Get-AppvClientConfiguration -Name PackageInstallationRoot).Value) oddly returns a string with batch-style environment variables (%programdata%\App-V).

1

There are 1 best solutions below

0
Theo On BEST ANSWER

You can use the [environment] type accelerator for that:

[environment]::ExpandEnvironmentVariables('%programdata%\App-V')

returns C:\ProgramData\App-V