One of the features about PowerCLI 4 Update 1 that I really like is the ability to read credentials from a credential store. A couple of new cmdlets really come in handy when you use the credential store.
New-VICredentailStoreItem and Get-VICredentialStoreItem
Rather than embed passwords in a script or stopping execution of the script so the user can enter the credentials, New-VICredentialStoreItem allows you to store the user name and password in an obfuscated XML file.
For example in my vCenter Server system named vc1.vmware.local my user name is admin and my password is vmware. I can store the credentials in a file with the New-CredentailStoreItem cmdlet.
New-VICredentialStoreItem -Host vc1.vmware.local -User admin -Password vmware -File C:\credentials.xml
The file is not a secure password repository and anyone that has access to the file has the ability to recover the passwords that are stored there. Still it does avoid having to re-enter the user name and password over and over again.
This example creates a new entry for the host in the file. If the file does not exist then the file is created. To read Credentials from the file, you use the Get-VICredentialStoreItem cmdlet.
$c = Get-VICredentialStoreItem -Host vc1.vmware.local -User admin -Password vmware -File C:\Credentials.xml
Now you have the credentails stored in the variable, you can use them in your connect cmdlet.
Connect-ViServer vc1.vmware.local -User $c.User -Password $c.Password
Ok a couple of warnings about this credentail file, it's not designed to be a secure password repository. Though the passwords in the file are obfuscated, anyone who has rights to read the file has the ability to recover the passwords from the file.