Jul 05 2022 05:15 AM
$env:UserProfile
Would be (as expected):
C:\Users\[YourUserProfileName]
$Profile = 'Profile'
$env:'User' + $Profile
${env:'User' + $Profile}
(Get-Item env:$UserProfile).value
Jul 05 2022 07:04 PM
Solution
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
Jul 06 2022 05:51 AM
Jul 05 2022 07:04 PM
Solution
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