PowerShell: Using Credential File For Connect-VIServer


To run a scheduled PS script against the vCenter server, you either hard code the credential in your script or use the credential file. Needless to say that credential file is better in terms of security, as the password is encrypted in the file.

Two steps to complete:

1) Create a credential file.

Add-PSSnapIn VMware.VimAutomation.Core
New-VICredentialStoreItem -host my-vcs-server -user jackie.chen -password ****** -file C:\Scripts\credfile.xml

2) Specify which credential file to use in the PS script.

Add-PSSnapIn VMware.VimAutomation.Core
$creds = Get-VICredentialStoreItem -file “C:\Scripts\credfile.xml”
Connect-viserver -Server $creds.Host -User $creds.User -Password $creds.Password

Advertisement

3 thoughts on “PowerShell: Using Credential File For Connect-VIServer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s