BSonPOSH took almost all the pain out of logging into Virtual Infrastructure with his get-credentials script. That was still too much typing for me. Every time I turned around I had timeout of my VC session. My solution a small function added to my profile.
################### Start VMWARE ##################################
# Load Admin credentials
# Modified from http://bsonposh.com/archives/338
$creds = New-Object System.Management.Automation.PsCredential(”Domain\User-adm”, `
(Get-Content “$env:homeshare\scripts\mycreds.txt” | ConvertTo-SecureString)
# Load Vmware
IF (!(Get-PSSnapin | ?{$_.name -eq “VMware.VimAutomation.Core”}
{
Add-PSSnapin VMware.VimAutomation.Core
}
# Add VMware Community Extentions
# Requires Powershell V2
Add-Module “$env:homeshare\scripts\VMWareExtenstions.psm1″
Function Get-VC([string]$VCServer = “DefaultVCServer”)
{
Get-VIServer -Server $VCServer -Credentials $creds | Out-Null
}
Set-Alias GVC Get-VC
################### End VMWARE ####################################
Now when I want to connect to my primary VC Server I type.
PS > . GVC
that’s dot space GCV…
NOTE: As far as how secure is this solution? Well, my password is stored in a file. That file cannot be interpreted by anyone other then me (similar to EFS). Additionally I know some would mock globally loading $creds. However, I work on an isolated network, and my execution policy is set to ALLSigned. I acknowledge that there is still a risk, but it’s one I can live with.
~Glenn
UPDATE: VMware has changed the get-viserver cmdlet to connect-viserver more to come…