New WSManInstance - PowerShell


Overview

The New-WSManInstance cmdlet creates a WS-Management (WSMan) instance that can be used to manage remote computers. WSMan is a protocol that allows for remote management of computers using web services. It is based on the SOAP and HTTP protocols, and it uses the Windows Management Instrumentation (WMI) infrastructure to access and manage data on remote computers.

Syntax

New-WSManInstance [-ComputerName] <string> [-Port] <uint16> [-Credential] <pscredential> [-ApplicationName] <string> [-URI] <string>

Options/Flags

  • -ComputerName: The name of the computer to which you want to connect. This parameter is required.
  • -Port: The port number to use for the connection. The default value is 5985.
  • -Credential: A PSCredential object that contains the user name and password to use for the connection. If this parameter is not specified, the current user’s credentials will be used.
  • -ApplicationName: The name of the application that will be making the connection. This parameter is optional.
  • -URI: The URI of the WSMan service to which you want to connect. The default value is http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2.

Examples

Simple Example

The following command creates a WSMan instance to connect to the local computer:

$instance = New-WSManInstance -ComputerName localhost

Complex Example

The following command creates a WSMan instance to connect to a remote computer and uses a specific port and credential:

$instance = New-WSManInstance -ComputerName remotecomputer -Port 8080 -Credential (Get-Credential)

Common Issues

One common issue that you may encounter when using the New-WSManInstance cmdlet is that the connection to the remote computer may be refused. This can happen if the remote computer’s firewall is blocking the connection, or if the remote computer is not running the WSMan service.

Integration

The New-WSManInstance cmdlet can be used with other PowerShell cmdlets to perform a variety of tasks. For example, you can use the New-WSManInstance cmdlet to create a connection to a remote computer, and then use the Invoke-WSManCommand cmdlet to execute commands on that computer.

  • Invoke-WSManCommand: Invokes a WSMan command on a remote computer.
  • Get-WSManInstance: Gets a WSMan instance.