Export (0) Print
Expand All
Expand Minimize

Converting VBScript's GetObject Function


Windows PowerShell


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

GetObject

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 its GetObject method:



	
[reflection.assembly]::LoadWithPartialName("'Microsoft.VisualBasic")
$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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft