When creating a connection to a remote computer, a user can specify the connection information such as the remote computer name, credentials, and the authentication level for the connection. The following examples illustrate how to connect to a remote computer by using different sets of credentials and how to access WMI information.
The following Windows PowerShell example shows setting the impersonation level:
In the preceding example, the user connects to a remote computer by using the same credentials (domain and user name) that they logged on with. The user also requested to use impersonation. Unlike the original VBScript example, a moniker string is not needed because the impersonation level is set by the "Impersonation" property. By default, the impersonation level is set to 3 (Impersonate).
The example lists all the instances of the Win32_Process class that are running on remote computer.
Note
You should specify the WMI namespace to connect to on the remote computer because it is possible that the default namespace is not the same on different computers.
The following Windows PowerShell example shows how to connect to a remote computer with different credentials and to set the impersonation level to 3, which is Impersonate:
In the preceding example, the computer name was assigned to the $Computer variable. The user connects to a remote computer by using specific credentials (domain and user name) and requests impersonation for the authentication level.
Note
The grave-accent character (`) is used to indicate a line break. It is equivalent to the underscore character (_) in VBScript.
The following Windows PowerShell example connects to a group of remote computers in the same domain by creating an array of remote computer names and then displaying names of the Plug and Play devices—instances of Win32_PnPEntity—on each computer:
To run the preceding Windows PowerShell script, you must be an administrator on the remote computers. Also, relating to the preceding example, note the following:
The computer names in the array must be enclosed in quotation marks because they are strings.
The objects returned by the Get-WmiObject are assigned to the $ColItems variable.
The range operator [] limited the list of Plug and Play devices to 48 instances. For more information, see About_Operators.
The "|" is the pipeline character. The object returned by ColItems is sent to the Format-List cmdlet.
The following Windows PowerShell example enables you to connect to a remote computer on a different domain. This example also displays the process names for instances of Win32_Process on the remote computer.
To run the preceding Windows PowerShell script, you must be an administrator on the remote computer.
In the preceding example, the user connects to a remote computer on a different domain and specifies a preferred locale. The Get-Credential command requests the user's credentials and assigns the credentials to an object. The example also lists the names of instances of the Win32_Process class that are running on the computer.
As a Windows Server hybrid administrator, you integrate Windows Server environments with Azure services and manage Windows Server in on-premises networks.