我正在尝试使用Power shell从注册表项读取值.这很简单,但是,一个特定的注册表项给我带来了麻烦. 如果我运行以下命令,我无法获得(默认)“$setting”的值. C:\Program Files\PowerGUI $setting = Get
如果我运行以下命令,我无法获得(默认)“$setting”的值.
C:\Program Files\PowerGUI> $setting = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\IniFileMapping\Autorun.inf"
C:\Program Files\PowerGUI> $setting
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\
CurrentVersion\IniFileMapping\Autorun.inf
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\
CurrentVersion\IniFileMapping
PSChildName : Autorun.inf
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.Core\Registry
(default) : @SYS:DoesNotExist
通常,我会做$setting.Attribute,或$setting.(默认).但是,这会导致以下错误:
C:\Program Files\PowerGUI> $setting.(default) The term 'default' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again. At :line:1 char:17 + $setting.(default <<<< )
如何获取“(默认)”属性的值?
提前致谢.
编辑不得不通过和旧脚本来解决这个问题.诀窍是你需要查看底层的PSObject来获取值.特别是看属性包
$a = get-itemproperty -path "HKLM:\Some\Path"
$default = $a.psobject.Properties | ?{ $_.Name -eq "(default)" }
您也可以使用索引器而不是使用过滤器技巧
$default = $a.psobject.Properties["(default)"].Value;
