เป็น RegistryKey คุณสมบัติของจริงข้อความวัตถุอยู่ใน 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 แอททริบิวต์,ตั้งแต่พวกเขาเป็น delimited โดยเครื่องหมาย: : ไม่ได้ดูเหมือนจะใช้เส้นสาย,ดังนั้นฉันดูหน่อยต่องแต่พบว่าพวกเขาแน่นอน 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

ค่าปริยายรูปแบบแฟ้มสื่อสำหรับลงชื่อ(เช่น: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ý
..................................................................................................................

ดังอยู่ในนี้หมวดหมู่

ดังคำถามอยู่ในนี้หมวดหมู่