19.2. How PowerShell Supports COM

PowerShell is built on the .NET Framework, and the framework already provides excellent COM support. For example, we can use the .NET infrastructure to get a hold of a .NET type that wraps a COM object and use the Activator class to create an instance of that type. This is how we can create an instance of the Internet Explorer browser using that approach:

PS> $ieType = [type]::GetTypeFromProgID("InternetExplorer.Application")
PS> $ieType.Name
__ComObject
PS> $ie = [Activator]::CreateInstance($ieType)
PS> $ie.Name
Windows Internet Explorer
PS>

There are two things to note in the preceding example. First, the type we get back from the GetTypeFromProgID() method has the odd name of __ComObject. All COM object wrappers ...

Get Pro Windows PowerShell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.