Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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 BSTR

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

Minimum supported client

Windows Vista [desktop apps only]

Minimum supported server

Windows Server 2008 [desktop apps only]

Redistributable

WinRM 1.1 (Windows Server 2003 R2, Windows Server 2003 with SP1, or Windows XP with SP2)

Header

Wsmandisp.h

IDL

Wsmandisp.idl

Library

WSManAutomation.lib

DLL

Wsmauto.dll

See also

ConnectionOptions

 

 

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.