All Versions

Typically, to access COM objects, these objects need to register themselves in the Windows Registry, and PowerShell needs the registered ProgID string to load the object.

Here is an example:

$object = New-Object -ComObject Scripting.FileSystemObject
$object.Drives 

Instead of using New-Object, you can also use .NET methods to achieve the same:

$type = [Type]::GetTypeFromProgID('Scripting.FileSystemObject')
$object = [Activator]::CreateInstance($type)
$object.Drives 

With the latter approach, you can even instantiate COM object that do not expose their ProgID. All you need is the GUID:

$clsid = New-Object Guid '0D43FE01-F093-11CF-8940-00A0C9054228'
$type = [Type]::GetTypeFromCLSID($clsid)
$object = [Activator]::CreateInstance($type)
$object.Drives

Twitter This Tip! ReTweet this Tip!

Anonymous