是的注册表项性真的串的对象,在powershell?

0

的问题

在powershell,这是可以获得一系列的 RegistryKeys 如下:

$hkeys = Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

当我检查的第一个元素这一阵列,这是我得到的:

    Hive: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall


Name                           Property                                                                                                                    
----                           --------                                                                                                                    
7-Zip                          DisplayName     : 7-Zip 21.03 beta (x64)                                                                                    
                               DisplayVersion  : 21.03 beta                                                                                                
                               DisplayIcon     : C:\Program Files\7-Zip\7zFM.exe                                                                           
                               InstallLocation : C:\Program Files\7-Zip\                                                                                   
                               UninstallString : "C:\Program Files\7-Zip\Uninstall.exe"                                                                    
                               NoModify        : 1                                                                                                         
                               NoRepair        : 1                                                                                                         
                               EstimatedSize   : 5237                                                                                                      
                               VersionMajor    : 21                                                                                                        
                               VersionMinor    : 3                                                                                                         
                               Publisher       : Igor Pavlov                                                                                               

Property 似乎有点奇怪,所以我看着进一步的成:

> $hkeys[0].property.gettype

IsPublic IsSerial Name                                     BaseType                                                                                        
-------- -------- ----                                     --------                                                                                        
True     True     String[]                                 System.Array                                                                                    

元素 property 属性,因为它们是分隔的一个冒号 : 似乎不像串,所以我看了一点进一步,但发现他们的确是 String 对象:

> $hkeys[0].property[0].gettype

IsPublic IsSerial Name                                     BaseType                                                                                        
-------- -------- ----                                     --------                                                                                        
True     True     String                                   System.Object                                                                                   

因为它们似乎是串的对象,我试图回声的第一个。 然而,它只显示了第一字符串的一部分,并不是之后的部分结肠:

> $hkeys[0].property[0]
DisplayName

我觉得有基本的东西,我不明白这里。 是的元件阵列真的 String 对象? 如果是这样,为什么不会之后的部分结肠出现?

arrays object powershell registry
2021-11-23 17:08:14
1

最好的答案

1

注册的对象有一个定义的格式输出其powershell使用时没有格式。 你可以读取更多的在这里 about_Format.ps1xml

你可以测试通过调用

$hkeys #formated with name:value, actually uses $hkeys | Out-Default

$hkeys | Format-Table Property #value won't show anymore

$hkeys | Format-List #value won't show anymore

默认的格式文件,用于注册表(ex:C:\Windows\System32\WindowsPowerShell\v1.0\Registry.format.ps1xml)将显示 财产 作为下

$result = (Get-ItemProperty -LiteralPath $_.PSPath |
    Select * -Exclude PSPath,PSParentPath,PSChildName,PSDrive,PsProvider |
    Format-List | Out-String | Sort).Trim()
$result = $result.Substring(0, [Math]::Min($result.Length, 5000) )
if($result.Length -eq 5000) { $result += "..." }
$result

和如你已经注意到,输出是一个 string[]

获得的实际价值在powershell你需要叫一个方法或者利用 Get-ItemProperty

$hkeys[0].getvalue('DisplayName') #you have to specify the property name
# or
$hkeys[0] | Get-ItemProperty
2021-11-23 21:18:45

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................