ConnectionOptions.UserName property

Sets and gets the user name of a local or a domain account on the remote computer. This property determines the user name for authentication. For more information, see Authentication for Remote Connections.

This property is read/write.

Syntax

ConnectionOptions.UserName As String

Property value

String that contains the user name of a local or a domain account on the remote computer.

If no value is supplied and the WSManFlagCredUsernamePassword flag is not set, the user name of the account that is running the script is used.

If no value is supplied and the WSManFlagCredUsernamePassword flag is set, the script prompts the user to enter the user name and password. If a valid user name and password are not entered, then an access denied error is returned.

Remarks

The following syntax is used to specify this property.

Set ConnectionOptions = wsman.CreateConnectionOptions
ConnectionOptions.UserName = "<UserName>"

You can supply UserName and Password for a domain account when using negotiate or Kerberos authentication, or for a local account with Basic authentication. To connect to a local account, the WSMan.CreateSession flags must contain the combination of the WSManFlagUseBasic flag and the WsmanFlagCredUserNamePassword flag. To connect to a domain account, the WSMan.CreateSession flags must contain the combination of the WSManFlagUseNegotiate flag and the WsmanFlagCredUserNamePassword flag, or the combination of the WSManFlagUseKerberos flag and the WsmanFlagCredUserNamePassword flag. For a domain account, UserName must be specified in the form "computer\username", where the "computer" part of the string can be either the name or the IP address. For more information, see Authentication for Remote Connections.

Set ConnectionOptions = Wsman.CreateConnectionOptions
ConnectionOptions.Username = "MyUserName"
ConnectionOptions.Password = "MyPassword"
Set NewSession = Wsman.CreateSession("127.0.51.1", _
  (WSMan.SessionFlagUseBasic Or _
  WSMan.SessionFlagCredUsernamePassword), ConnectionOptions)

For connecting to a domain account, the WSMan.CreateSession flags must contain the combination of the WSManFlagUseNegotiate flag and the WsmanFlagCredUserNamePassword flag for connecting to a domain account, which requires Negotiate authentication.

Set ConnectionOptions = Wsman.CreateConnectionOptions
ConnectionOptions.Username = "MyUserName"
ConnectionOptions.Password = "MyPassword"
Set NewSession = Wsman.CreateSession("127.0.51.1", _
  (WSMan.SessionFlagUseNegotiate Or _
  WSMan.SessionFlagCredUsernamePassword), ConnectionOptions)

Requirements

Requirement Value
Minimum supported client
Windows Vista
Minimum supported server
Windows Server 2008
Header
WSManDisp.h
IDL
WSManDisp.idl
Library
WSManDisp.tlb
DLL
WSMAuto.dll

See also

ConnectionOptions