Export (0) Print
Expand All
Expand Minimize
1 out of 4 rated this helpful - Rate this topic

Converting VBScript's CreateObject Function


Windows PowerShell


Definition: Creates and returns a reference to an Automation object.

CreateObject

In Windows PowerShell you create new COM objects by using the New-Object Cmdlet. To do so call New-Object, passing the Cmdlet the -comobject parameter, which tells Windows PowerShell to create a new COM object rather than, say, a new .NET Framework object. The -comobject parameter is then followed by the ProgID of the COM object.

For example, the following two commands create an instance of Microsoft Excel and then, just to prove that the first command did create an instance of Excel, the second command makes the application visible onscreen:


$a = new-object -comobject Excel.Application
$a.visible = $True

Incidentally, when using the New-Object Cmdlet you might want to add the -strict parameter, like so:


$a = new-object -comobject Excel.Application -strict

That helps ensure that you are working with a true COM object and not a COM wrapper around a .NET object.


Return to the VBScript to Windows PowerShell home page

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.