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')
复制代码 http://powershell.com/cs/blogs/tips/archive/2014/02/10/reading-stringexpand-registry-values.aspx |