windowspowershellbatch-fileenvironment-variablesappv

Interpret string with batch-style environment variables in Powershell


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).


Solution

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

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

    returns C:\ProgramData\App-V