Board logo

标题: [转载代码] [PowerShell每日技巧]读取包含扩展字符(如%SystemRoot%)的注册表键值(20140210) [打印本页]

作者: DAIC    时间: 2014-2-18 13:35     标题: [PowerShell每日技巧]读取包含扩展字符(如%SystemRoot%)的注册表键值(20140210)

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:
  1. $path = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion'
  2. $key = Get-ItemProperty -Path $path
  3. $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:
  1. $path = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion'
  2. $key = Get-Item -Path $path
  3. $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:
  1. $path = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion'
  2. $key = Get-Item -Path $path
  3. $key.GetValueKind('DevicePath')
复制代码
http://powershell.com/cs/blogs/tips/archive/2014/02/10/reading-stringexpand-registry-values.aspx




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2