Das folgende Beispiel zeigt wie man gezielt PowerShell oder Umgebungsvariablen in einem String auflösen kann:
# Test string (Please note I use ' ' and not " " to make sure they are not expanded)
$String = 'Test string with env variable [$env:WinDir] and powershell variable [$PSHOME]'
# Expand Environment Variables in a string
[System.Environment]::ExpandEnvironmentVariables($String)
# Expand PowerShell Variables in a string
$ExecutionContext.InvokeCommand.ExpandString($String)