O'Reilly logo

Windows PowerShell 4.0 for .NET Developers by Sherif Talaat

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

Working with COM

As is the case with WMI and XML, PowerShell also supports working with the COM type of objects. In this section, we will understand how COM works in PowerShell using two interesting examples that cover COM with Internet Explorer and Microsoft Excel.

Creating an instance of a COM object

In order to create an instance of a COM object, we use the New-Object cmdlet with the -ComObject parameter and ProgID as an argument, where the ProgID is the friendly name of the COM class used during class registration. Thus, the final command should look like this:

#create new COM object
PS C:\> $com = New-Object –ComObject <ProgID>

Automating Internet Explorer with COM and PowerShell

As mentioned earlier, the ProgID parameter is required to create ...

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