New WSManSessionOption - PowerShell


Overview

The New-WSManSessionOption command creates a new session option object for use with the New-WSManSession cmdlet. Session options allow you to customize the behavior of a WS-Management session, such as specifying the authentication method, timeouts, and security settings.

Syntax

New-WSManSessionOption [-AllowImplicitCredentialDelegation] [-AuthenticationMechanism <AuthenticationMechanism>] [-CertificateThumbprint <string>] [-Timeout <int>]

Options/Flags

  • -AllowImplicitCredentialDelegation: Allows the session to implicitly delegate credentials to remote servers.
  • -AuthenticationMechanism: Specifies the authentication mechanism to use. Valid values are: Basic, Digest, Kerberos, Negotiate, CredSSP, WinRM, Certificate.
  • -CertificateThumbprint: Specifies the thumbprint of the certificate to use for authentication.
  • -Timeout: Specifies the timeout value in seconds for the session. The default is 300 seconds.

Examples

Example 1: Create a session option object with basic authentication

$sessionOption = New-WSManSessionOption -AuthenticationMechanism Basic

Example 2: Create a session option object with Kerberos authentication

$sessionOption = New-WSManSessionOption -AuthenticationMechanism Kerberos

Example 3: Create a session option object with a specific timeout value

$sessionOption = New-WSManSessionOption -Timeout 600

Common Issues

  • Error: “The value specified for the ‘AuthenticationMechanism’ parameter is not valid.”
    Solution: Ensure that you are using a valid authentication mechanism. Refer to the -AuthenticationMechanism parameter description for the list of valid values.
  • Error: “The certificate specified by the ‘CertificateThumbprint’ parameter was not found.”
    Solution: Ensure that the certificate is installed on the local computer and that you have the correct thumbprint.

Integration

The New-WSManSessionOption command can be used with the New-WSManSession cmdlet to create a WS-Management session with the specified options. For example:

$session = New-WSManSession -ComputerName server1 -SessionOption $sessionOption
  • New-WSManSession
  • Get-WSManSessionOption
  • Set-WSManSessionOption