Reputation: 952
I am scripting a solution that requires passing %USERPROFILE% to the registry in local_machine. For example
DotJetFolder=%USERPROFILE%\JetFolder
But it seems like registry doesn't understand this format. Looking for ideas on how to implement it. This for an RDS solution where we can't pre-determine the user profile.
Is there any way to pass this sort of variable to the registry.
Upvotes: 1
Views: 4592
Reputation: 469
From what I understand, you want to have a sub for "%USERPROFILE%"
$temp = "$env:USERPROFILE" + "\Jet"
Write-Host $temp
Hope it Helps!
BR
Upvotes: 0
Reputation: 200273
You need to create the value as a REG_EXPAND_SZ value if you want environment variables in the string to be expanded when Windows reads the value. In PowerShell the creation of such a value would look somewhat like this:
$key = 'HKLM:\some\where'
$name = 'DotJetFolder'
$value = '%USERPROFILE%\JetFolder'
Set-ItemProperty -Path $key -Name $name -Value $value -Type ExpandString
Upvotes: 1