3

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

yanlend
  • 450
  • 3
  • 10

1 Answers1

6

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

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

returns C:\ProgramData\App-V

Theo
  • 57,719
  • 8
  • 24
  • 41