Forum Discussion

sglines's avatar
sglines
Copper Contributor
Jul 05, 2022
Solved

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:      ...
  • LainRobertson's avatar
    Jul 06, 2022

    sglines 

     

    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

Resources