Using PowerShell to log into VMware vSphere Web Client

Powershell is WAY better than logging in like a caveman

If you are running VMware vSphere 6.5 or above, you have been forced to adopt the web client for your administration of vSphere.  The full windows client has been deprecated and removed.  You are now stuck logging in every time with your credentials on a webpage that will timeout every so often.

Thankfully, Sam Jacobs wrote up a quick little PowerShell script to make credential entering a little easier.  Check out the note he sent over.

The following is a simple PowerShell script for those of you who frequently log into vCenter.

I got tired of re-entering my credentials every time, so I decided to speed things up a bit.

The script was originally written for my environment but should work for your environments by modifying a few variables at the top of the script. Your credentials are securely stored in a location of your choosing, but can only be decrypted by your security context. That means that even if someone got hold of your credentials file, they would not be able to use them.

Step 1
Before using the script for the first time, you must securely store your credentials with the following PowerShell commands (the directory for your password must already exist). This only needs to be done once.

$creds = Get-Credential
$pwLocation = “H:\PowerShell\Credentials\vCenterLogin.txt”
$creds.Password | ConvertFrom-SecureString | Set-Content $pwLocation

Step 2
Save the script below (vCenterLogin.ps1), making sure to modify the variables $userName and $pwLocation if necessary.

Step 3
Your system may have restrictions on PowerShell execution. To bypass any restrictions, open a PowerShell session, change to the directory where your script is located, and enter:

PowerShell.exe -ExecutionPolicy ByPass -File vCenterLogin.ps1

Please close your IE window once you logoff vCenter.

You can download the latest version of this script here on GitHub.

Please let me know if you have any questions/comments.

Sam Jacobs

You can follow Sam on Twitter at @WIGuru.