O'Reilly logo

Pro Windows PowerShell by Hristo Deshev

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required