Forum Discussion
sglines
Jul 05, 2022Copper Contributor
Issue combining variable and strings to create an environment variable output
I'm trying to combine some variable and string values in a script so that when the final environment variable is declared, PowerShell recognizes it. For example, the output of: ...
- Jul 06, 2022
While I don't understand the use case, if you're contrived example is attempting to concatenate "User" and "Profile" whilst using $env, you can achieve this using the following (based on your initial example.)
$Profile = "Profile"; Invoke-Expression -Command "`$env:User$Profile";
Cheers,
Lain
LainRobertson
Jul 06, 2022Silver Contributor
While I don't understand the use case, if you're contrived example is attempting to concatenate "User" and "Profile" whilst using $env, you can achieve this using the following (based on your initial example.)
$Profile = "Profile";
Invoke-Expression -Command "`$env:User$Profile";
Cheers,
Lain
- sglinesJul 06, 2022Copper ContributorThat absolutely worked. I really appreciate the input!