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

Converting the Windows Script Host CreateObject Method


Windows PowerShell


Definition: Creates a COM object.

CreateObject


To create a COM object using Windows PowerShell all you have to do is call the New-Object cmdlet, taking care to precede the application’s ProgID with the –com parameter. For example, this command creates an instance of Microsoft Excel (Excel.Application), and then sets the Visible property to True, enabling you to view that instance of Excel onscreen:


$a = New-Object -com Excel.Application
$a.Visible = $True


As you can see, there’s no need to enclose the ProgID in quotation marks. But what if you’re a long-time VBScript scripter and you’re used to enclosing ProgIDs in quotation marls? Well, here’s an idea: go ahead and enclose the ProgID in quotation marks. This block of code will also create a running instance of Microsoft Excel that you can see onscreen:


$a = New-Object -com "Excel.Application"
$a.Visible = $True



See conversions of other Windows Script Host methods and properties.
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.