Converting VBScript's GetObject Function

Definition: Returns a reference to an Automation object from a file.


OK, we’ll level with you: we’re taking the easy way out on this one. Although Windows PowerShell does not include a GetObject command, it is possible to load the Microsoft.VisualBasic assembly and then use the Interaction class and itsGetObject method:

$a= [Microsoft.VisualBasic.Interaction]::GetObject("WinNT://atl-ws-01/Administrator")

That part’s easy. To actually use this object reference is far more complicated, requiring the use of binding flags and the InvokeMember method, and, well, it goes way beyond what we can cover in this introductory manual. The best thing to do? Assume that there is no GetObject equivalent and forget about it. The second best thing to do: Check this Web site for an example of using the Visual Basic .NET GetObject method from within Windows PowerShell.

Return to the VBScript to Windows PowerShell home page