Information2 use cookies to help you have a superior and more admissible browsing experience on our website. Privacy Policy
Loading...
A vCenter connection gives you visibility across all managed ESXi hosts and clusters in a single session.
Connecting directly to an ESXi host limits your scope to that one machine, so cross-host operations like VM migration, cluster-level queries, and shared datastore browsing all require going through vCenter.
Many PowerCLI scripts also depend on services that only run on vCenter. Pointing those scripts at a standalone ESXi host will cause certain cmdlets to fail outright.
This section covers what you need in place before connecting, the basic Connect-VIServer syntax, and 6 methods suited to different environments and security requirements.
Before connecting, your workstation requires the VMware PowerCLI module. Run the following in an administrative PowerShell session to install it for your user profile:
Install-Module -Name VMware.PowerCLI -Scope CurrentUser
You also need an execution policy that allows scripts to run:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
Finally, confirm that your workstation can reach vCenter over HTTPS port 443, and that you have valid credentials — either a local vSphere account or an Active Directory domain account.
The minimal syntax passes your credentials directly to Connect-VIServer:
Connect-VIServer -Server "vcenter.example.com" -User "administrator@vsphere.local" -Password "yourpass"
Key parameters:
-Server: The FQDN or IP address of your vCenter instance.-User: The username for authentication.-Password: The account password. Enclose the value in single quotes if it contains special characters.-Port: Overrides the default port when your environment uses a non-standard one.-Protocol: Specifies HTTP or HTTPS. HTTPS is the default.PowerCLI offers several authentication methods. Choose based on your security requirements and whether the script runs interactively or unattended.
1. Username and Password
Passing plaintext credentials directly in the command is the simplest approach. It works for quick tests in isolated lab environments but should never be used in production scripts.
2. PSCredential Object
A credential object avoids hardcoding passwords in plain text. The Get-Credential cmdlet prompts for a password and stores it securely in memory:
$Credentials = Get-Credential
Connect-VIServer -Server "vcenter.example.com" -Credential $Credentials
This is safer for interactive sessions since the password is never stored as a plain string.
3. VICredentialStore
For unattended or scheduled scripts, store credentials in the local encrypted credential store:
New-VICredentialStoreItem -Server "vcenter.example.com" -User "sa-automation@vsphere.local" -Password "SecurePass123"
Connect-VIServer -Server "vcenter.example.com"
PowerCLI retrieves the saved credentials automatically on subsequent connections. Note that the credential store is local to the machine and user account running the script.
4. Integrated (Pass-Through) Authentication
If your workstation is domain-joined and vCenter has an Active Directory identity source configured, PowerCLI can authenticate using your current Windows session credentials via Kerberos or NTLM:
Connect-VIServer -Server "vcenter.example.com"
No username or password is required. Keep in mind that this only works for the logged-in user — scheduled tasks running as a different account will need credentials stored via the VICredentialStore instead.
5. Session ID Reuse
You can save an existing session ID and pass it to a subsequent connection within the same script to skip re-authentication:
$VIConn = Connect-VIServer -Server "vcenter.example.com" -Credential (Get-Credential)
$SavedSessionId = $VIConn.SessionId
# Later in the same script:
Connect-VIServer -Server "vcenter.example.com" -Session $SavedSessionId
This is useful for multi-step scripts that need to reconnect mid-execution. Session IDs are tied to the server session and cannot be reused across separate PowerShell processes.
6. SAML / OAuth (Federated Identity)
Environments with external identity providers such as AD FS, Entra ID, or PingFederate require token-based authentication. The correct flow involves obtaining an OAuth security context first, then exchanging it for a SAML context before connecting:
# Step 1: Obtain an OAuth security context from your identity provider
$OAuthCtx = New-OAuthSecurityContext `
-TokenEndpointUrl "https://adfs.example.com/adfs/oauth2/token/" `
-AuthorizationEndpointUrl "https://adfs.example.com/adfs/oauth2/authorize/" `
-RedirectUrl "http://localhost:8844/auth" `
-ClientId "powercli-native"
# Step 2: Exchange for a SAML security context
$SamlCtx = New-VISamlSecurityContext -VCenterServer "vcenter.example.com" -OAuthSecurityContext $OAuthCtx
# Step 3: Connect using the SAML context
Connect-VIServer -Server "vcenter.example.com" -SamlSecurityContext $SamlCtx
PowerCLI supports simultaneous connections to several vCenter instances. This is useful for reporting or configuration scripts that span multiple environments.
To connect to a list of servers in a loop:
$vCenters = @("vcenter1.example.com", "vcenter2.example.com")
foreach ($vc in $vCenters) {
Connect-VIServer -Server $vc -Credential (Get-Credential)
}
When multiple connections are active, PowerCLI tracks them through two global variables. $DefaultVIServer references the most recently connected server. $DefaultVIServers holds all active connections as an array.
By default, PowerCLI runs cmdlets against the single server in $DefaultVIServer. To target all connected instances simultaneously, switch to multiple mode:
Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -Confirm:$false
For environments with Enhanced Linked Mode, the -AllLinked parameter connects to all vCenter instances in the federation with a single command:
Connect-VIServer -Server "vcenter1.example.com" -AllLinked
Always confirm the session is active before running other cmdlets. Use these three commands to inspect your current connection state.
Query the most recently connected server:
$DefaultVIServer
List all active connections in the current PowerShell session:
Get-VIServer
Review all servers currently in the default targets list:
$DefaultVIServers
Closing active sessions properly is an important part of script hygiene in PowerCLI.
To disconnect from a specific vCenter, run Disconnect-VIServer with -Confirm:$false to skip the confirmation prompt:
Disconnect-VIServer -Server "vcenter.example.com" -Confirm:$false
If your script opened connections to multiple environments, use a wildcard to close all active sessions at once:
Disconnect-VIServer -Server * -Force -Confirm:$false
Clean disconnection matters because active sessions continue consuming resources on the vCenter Server. Leaving orphaned connections open can exhaust the session limit, which may temporarily block other administrators or scripts from connecting.
Some administrators manually remove entries from the $DefaultVIServers array instead of using the cmdlet. This only hides the connection from the current PowerShell session — it does not terminate the underlying API session on vCenter. Always use Disconnect-VIServer to ensure sessions are fully closed.
The errors below cover the three most common failure points: certificate validation, Windows authentication, and basic network connectivity.
This error occurs when vCenter uses a self-signed certificate, or when the MACHINE_SSL certificate has been replaced but is not trusted by your workstation. PowerCLI blocks the connection by default.
For lab environments, configure PowerCLI to ignore the certificate check:
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
For staging, use Warn mode to allow the connection while logging a console warning:
Set-PowerCLIConfiguration -InvalidCertificateAction Warn -Confirm:$false
In production, install a CA-signed certificate on the vCenter Server, or add the VMCA root certificate to the trusted root store on your management workstation.
If you encounter a TLS mismatch error when connecting to older vCenter versions or environments that have disabled TLS 1.0/1.1, force PowerShell to negotiate TLS 1.2 before connecting:
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
Connect-VIServer -Server "vcenter.example.com" ...
For Integrated Windows Authentication to work, vCenter requires an Active Directory identity source configured in the SSO settings. Verify this before attempting pass-through authentication.
Scripts running via Windows Task Scheduler fail here if the task runs under a local system account rather than a domain account with vCenter access. Check the account context the scheduled task uses.
When integrated authentication is not practical for unattended scripts, store encrypted credentials in the VICredentialStore instead:
New-VICredentialStoreItem -Server "vcenter.example.com" -User "domain\sa-automation" -Password "SecurePassword"
Start by checking that your firewall allows outbound HTTPS traffic on port 443 to the vCenter Server.
Verify that your -Server value uses the correct FQDN or IP. For IPv6 addresses, enclose the address in square brackets:
Connect-VIServer -Server "[fe80::20c:29ff:fe00:1122]"
If your password contains special characters like $, wrap the entire string in single quotes to prevent PowerShell from evaluating them:
Connect-VIServer -Server "vcenter.example.com" -User "administrator@vsphere.local" -Password 'P@$$word!'
If system proxy settings are routing PowerCLI traffic away from internal subnets, bypass them with:
Set-PowerCLIConfiguration -ProxyPolicy NoProxy -Confirm:$false
PowerCLI gives you control over your vCenter environment — but automation alone does not protect it. When a VM is deleted, a host fails, or a configuration change goes wrong, you need a recovery layer that works independently of your scripting pipeline.
i2Backup fills that role for VMware environments.
For teams managing environments that go beyond backup — such as real-time replication between production and disaster recovery sites — i2Availability provides application-level high availability with automated failover. For database replication and cross-platform data sync, i2Stream handles real-time replication across heterogeneous database environments.
Connecting PowerCLI to vCenter is the starting point for almost any vSphere automation task. Once the session is established — whether through a credential object, the VICredentialStore, or a federated identity provider — you gain centralized access to every host, cluster, and datastore in your environment.
The methods and fixes covered in this guide address the most common barriers: certificate errors, authentication failures, and network-level blocks. Keeping sessions clean with proper disconnects and understanding how $DefaultVIServers behaves across multiple connections will save time when scripts behave unexpectedly.
Managing vCenter through PowerCLI gives you operational control, but it does not replace a dedicated protection layer. Pairing your automation workflows with Info2soft’s i2Backup ensures that the VMs and workloads you manage are recoverable when something goes wrong.