When you read a Registry value of type StringExpand, it will always automatically expand any environment variables contained in the text.
This example will read the system device path from your Registry:
$path = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion' $key = Get-ItemProperty -Path $path $key.DevicePath
The result will be an actual path. That is OK unless you wanted to get the original (unexpanded) Registry value. Here is the example that reads the original value:
$path = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion' $key = Get-Item -Path $path $key.GetValue('DevicePath', '', 'DoNotExpandEnvironmentNames')
Accessing Registry values this way will get you another valuable piece of information: you can now also find out the value's data type:
$path = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion' $key = Get-Item -Path $path $key.GetValueKind('DevicePath')