Disconnect WSMan - PowerShell


Overview

The Disconnect-WSMan cmdlet disconnects the current session from a remote Windows Management (WS-Management) server. WS-Management is a standard protocol for managing computers remotely.

Syntax

Disconnect-WSMan [[-ConnectionUri] <Uri>]

Options/Flags

  • -ConnectionUri: Specifies the URI of the WS-Management connection to disconnect from. If not specified, the current connection is disconnected.

Examples

Example 1: Disconnecting from the current session

Disconnect-WSMan

Example 2: Disconnecting from a specific session

$uri = New-Object System.Uri "http://server01:80/wsman"
Disconnect-WSMan -ConnectionUri $uri

Common Issues

Error: “The WinRM client cannot process the request because the transport was closed prematurely.”

This error can occur if the remote server does not support WS-Management. Ensure that WS-Management is enabled on the remote server.

Integration

Disconnect-WSMan can be combined with other PowerShell cmdlets to manage remote computers. For example, you can use Invoke-Command to run commands on a remote computer and then Disconnect-WSMan to disconnect the session.