如何在PowerShell中查看可用COM对象的描述列表?

问题描述 投票:1回答:3

当我执行此powershell命令以获取与前缀“ Python”匹配的正在运行的COM对象的列表时,将得到以下输出:

PS C:\Users\{path-to-arbitrary-directory}> Get-ChildItem HKLM:\Software\Classes | Where-Object {
        $_.PSChildName -match '^Python[\.a-zA-Z]*$' } | Select-Object


    Hive: HKEY_LOCAL_MACHINE\Software\Classes


Name                           Property                                                                                                                                                                     
----                           --------                                                                                                                                                                     
Python                         (default) : Python ActiveX Scripting Engine                                                                                                                                  
Python.Dictionary              (default) : Python Dictionary                                                                                                                                                
Python.Interpreter             (default) : Python Interpreter                                                                                                                                               
Python.TestServer              (default) : Python Test COM Server            

我想做的只是获取名称和描述的列表。

当前,我可以使用此命令获取名称:

PS C:\Users\{path-to-arbitrary-directory}> Get-ChildItem HKLM:\Software\Classes | Where-Object {
            $_.PSChildName -match '^Python[\.a-zA-Z]*$' } | Select-Object PSChildName,Property

PSChildName        Property   
-----------        --------   
Python             {(default)}
Python.Dictionary  {(default)}
Python.Interpreter {(default)}
Python.TestServer  {(default)}

但是我无法终生想出如何显示执行第一条命令时看到的描述?

这是我想要的输出:

Name                           Description
----                           --------                                                                                                                                                                     
Python                         Python ActiveX Scripting Engine                                                                                                                                  
Python.Dictionary              Python Dictionary                                                                                                                                                
Python.Interpreter             Python Interpreter                                                                                                                                               
Python.TestServer              Python Test COM Server  

((如果有帮助,我也可以使用此命令查看描述)

PS C:\Users\{path-to-arbitrary-directory}> Get-ChildItem HKLM:\Software\Classes | Where-Object {
            $_.PSChildName -match '^Python[\.a-zA-Z]*$' } | Get-ItemProperty


(default)    : Python ActiveX Scripting Engine
PSPath       : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\Software\Classes\Python
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\Software\Classes
PSChildName  : Python
PSProvider   : Microsoft.PowerShell.Core\Registry

...
powershell com
3个回答
1
投票

现有的答案很有帮助,但让我添加一些背景信息

默认输出显示目标键值的原因是默认输出格式枚举了它们,如以下命令所示:

(Get-FormatData Microsoft.Win32.RegistryKey -PowerShellVersion $PSVersionTable.PSVersion).FormatViewDefinition.Control.Rows.Columns.DisplayEntry.Value

显示:

PSChildName # column 1 - below is the script block that defines column 2
    $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

如您所见,Get-ItemProperty在后台被调用以枚举键的值。

顺便说一句:当从remote注册表中检索值时,这种作为格式一部分枚举值的方法会导致输出错误-请参见this answer。>


[如其他答案所示,虽然在Get-ItemProperty的脚本块中调用Get-ItemProperty肯定有效,但还有一种更有效的选择:您可以调用calculated property实例的.GetValue()方法,[ C0]输出:

Microsoft.Win32.RegistryKey

2
投票

一种方法是使用计算出的属性。您可以使用Microsoft.Win32.RegistryKey获取Get-Item注册表项属性的值。然后,您可以将该值显示为计算所得的属性。


2
投票

尝试一下。这样的事情在功能上更好。

© www.soinside.com 2019 - 2024. All rights reserved.