Connect-VIServer

Synopsis

Connects to a vSphere server.

Syntax

Connect-VIServer [-Server] <String[]> [-Port <Int32>] [-Protocol <String>] [-Credential <PSCredential>] [-User <String>] [-Password <String>] [-Session <String>] [-NotDefault] [<CommonParameters>]

Related Commands

Disconnect-VIServer

Detailed Description

Connects to a vSphere server. The cmdlet starts a new session or re-establishes a previous session with a vSphere server using the specified parameters.
You can have more than one connections to the same server. To disconnect from a server, you need to close all active connections to this server.
vSphere PowerCLI supports working with multiple default servers. If you select this option, every time when you connect to a different server using Connect-VIServer, the new server connection is stored in an array variable together with the previously connected servers, unless the -NotDefault parameter is set. This variable is named $DefaultVIServers and its initial value is an empty array. When you run a cmdlet and the target servers cannot be determined from the specified parameters, the cmdlet runs against all servers stored in the array variable. To remove a server from the $DefaultVIServers variable, you can either use Disconnect-Server to close all active connections to the server, or modify the value of $DefaultVIServers manually.

If you choose to work with a single default server, when you run a cmdlet and the target servers cannot be determined from the specified parameters, the cmdlet runs against the last connected server. This server is stored in the $defaultVIServer variable, which is updated every time you establish a new connection. Working with a single default server is deprecated and will be removed in a future release.

To switch between single and multiple default servers working mode, use the Set-PowerCLIConfiguration cmdlet.

Parameters

NameDescriptionRequired?Pipeline InputDefault Value
ServerSpecify the IP address or the DNS name of the vSphere server to which you want to connect.truefalse
PortSpecify the port on the server you want to use for the connection.falsefalse
ProtocolSpecify the internet protocol you want to use for the connection. It can be either http or https.falsefalse
CredentialSpecify a PSCredential object that contains credentials for authenticating with the server. Passing values to this parameter through a pipeline is deprecated and will be disabled in a future release.falsetrue (ByValue)
UserSpecify the user name you want to use for authenticating with the server. If the -Credential parameter is also specified, this parameter is ignored. Passing values to this parameter through a pipeline is deprecated and will be disabled in a future release.falsetrue (ByValue)
PasswordSpecifies the password you want to use for authenticating with the server. If the -Credential parameter is also specified, this parameter is ignored.falsefalse
SessionSpecify the ID of an existing vSphere server session you want to reestablish.falsefalse
NotDefaultIndicate that you do not want to include the server to which you connect into the $defaultVIServers variable.falsefalse

Input Type

Return Type

VMware.VimAutomation.Types.VIServer

Notes

Examples

--------------  EXAMPLE 1 --------------

C:\PS>Connect-VIServer -Server 10.23.112.235 -Protocol https -User Administrator
 -Password pass01


Connects to a vSphere server using the User and Password parameters.


Name                                    Port
----                                    ----
10.23.112.235                           443

--------------  EXAMPLE 2 --------------

C:\PS>$srv = Connect-VIServer 10.23.115.133 -User Admin -Password Pass01
 
Connect-VIServer 10.23.115.133 -Session $srv.SessionId


Connects to a vSphere server and restores a previous session. Note that when res
toring a session, user does not need to specify credentials for authenticating w
ith the server.


Name                                    Port
----                                    ----
10.23.112.236                           442

Copyright © 1998 - 2009 VMware, Inc. All rights reserved.