44

In Powershell I can create COM objects which can be used, for example, to control Microsoft Office applications:

$excel = New-Object -com "Excel.Application"
$excel.visible = $true

How can I list all of the available COM objects that can be created in Powershell?

John Channing
  • 6,501
  • 7
  • 45
  • 56

3 Answers3

71

I found this powershell one-liner script that supposedly lists all COM objects.

gci HKLM:\Software\Classes -ea 0| ? {$_.PSChildName -match '^\w+\.\w+$' -and
(gp "$($_.PSPath)\CLSID" -ea 0)} | ft PSChildName

let us know if it works!

Jeff Atwood
  • 63,320
  • 48
  • 150
  • 153
  • 2
    I can confirm that it does list all the registered COM objects. Whether or not they implement the COM interface correctly is a whole different issue. :) – EBGreen Mar 19 '09 at 13:44
  • 3
    *my two cents:* `HKLM\Software\Classes`actually corresponds to `HKCR` – ZJR May 06 '11 at 20:59
  • 4
    And my two cents: rather than piping to `ft PSChildName`, pipe to `select -ExpandProperty PSChildName`. That returns the results as an array that can be filtered with **-match** or **Select-String**. – Adi Inbar Aug 02 '14 at 18:06
  • this script above did not work for me, instead this script works: http://www.powershellmagazine.com/2013/06/27/pstip-get-a-list-of-all-com-objects-available/ – denfromufa Sep 10 '14 at 19:53
  • wben you do `Format-Text`, you will not get `string`s, but some formatting related classes – fbehrens Aug 09 '19 at 10:24
  • @Jeff Can you explain purpose of this filter `$_.PSChildName -match '^\w+\.\w+$'` – Nilesh Feb 20 '20 at 17:47
7

Use OleView.exe from Microsoft. I think it may come with Visual Studio. If not, you can find it in the Windows SDK. That's a big download; you can either download the whole thing or you could experiment with downloading it piecemeal using the setup.exe installer.

Once in OleView, look under "type libraries". Excel for instance appears under "Microsoft Exel".

dan-gph
  • 16,301
  • 12
  • 61
  • 79
6

Another option that should be noted is through WMI:

Get-WMIObject Win32_ClassicCOMClassSetting
JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
  • running this produced an infinite loop – CoderDennis Jun 19 '09 at 18:33
  • 4
    Since it isn't a loop, it can not possibly be an infinite loop. It will take a long time to run because there are MANY COM components. – JasonMArcher Jun 27 '09 at 22:45
  • 1
    That does not list the ActiveX control I am looking for. This does https://gist.github.com/810398 – Justin Dearing May 11 '11 at 21:49
  • ActiveX Controls won't always have a progid, or more correctly, a programmatic identifier (which is what the scripts above are discovering in HKCR. But they always have a CLSID. If you are just trying to determine whether the ActiveX Control is installed so you can uninstall it, search for its CLSID in HKCR/CLSID. – Alan McBee Aug 31 '15 at 03:21