Converting VBScript's Set Statement

Windows PowerShell

Definition: Assigns an object reference to a variable or property, or associates a procedure reference with an event.


You do not need to use the Set statement (or any sort of equivalent keyword/command) in order to create an object reference in Windows PowerShell. Instead, you simply use the New-Object Cmdlet, followed by (in the case of COM objects) the -comobject parameter and the ProgID of the object to be created.

For example, the following two commands create an instance of Microsoft Excel and then, just to prove that the instance of Excel was created, make the application visible onscreen:

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

Return to the VBScript to Windows PowerShell home page