Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

Converting the Windows Script Host GetObject Method


Windows PowerShell


Definition: Retrieves an existing object with the specified ProgID, or creates a new one from a file.

GetObject


The Get-Object method is used to connect to a COM object that is already up and running; this is typically used to connect to WMI or ADSI. (To connect to another object, such as Excel or Word, you need to use VBScript’s GetObject method. And yes, same name, slightly different functionality.)

Windows PowerShell doesn’t really have anything that corresponds directly to the GetObject method. However, you can use PowerShell’s type adapters as a way to connect to existing objects like WMI or ADSI. For example, this command provides a shortcut method for retrieving a specific object in WMI:


[WMI] 'Win32_Service.Name="Alerter"'


Meanwhile, this command connects to the local administrator account on the computer atl-fs-001:


$a = [ADSI]"WinNT://atl-fs-001/administrator"


Etc.


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.