VMware Cloud Community
ms5812
Enthusiast
Enthusiast
Jump to solution

Need assistance with creating and then using stored credentials

I am attempting to automate several scripts to use the

storing credentials for Alans vCheck script

That post is exactly what I would like to accomplish:

## save the credentials to the VI credential store one time
Connect-VIServer -Server myVC0.domain.com -Credential (Get-Credential domain\user0) -SaveCredentials

You could also add items to the VI credential store using the New-VICredentialStoreItem cmdlet.  Using that cmdlet looks something like:

## add credential to the store
New-VICredentialStoreItem -Host myVC0.domain.com -User domain\user0 -Password supersecretpass

I am looking for a way to run my PowerCLI scripts by selecting a VC and calling the -user and -password. I am not sure in what format to create this? Below is how I am calling the VC.

[CmdletBinding()]

param (
    [Parameter(Position = 0, Mandatory = $true)]
    [System.String]
    $VirtualCenterServer,
    [Parameter(Position = 1)]
    [System.String]
    $ClusterName,
    [Parameter(Position = 2)]
    [System.Boolean]
    $asLocalUser = $true
)

$user = C:\vmware\user.txt (not sure what file type is needed)

$password = C:\vmware\password.txt (not sure what file type is needed)

New-VICredentialStoreItem -Server $VirtualCenterServer -User $user -Password $password


and then calling the script/scripts for the -user and -password
Connect-VIServer -Server $VirtualCenterServer -User $user -Password $password | Out-Null

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The output from the New-VICredentialStoreItem is an XML file.

You can use the credenial store as follows

# Save

New-VICredentialStoreItem -Host $VirtualCenterServer  -User Admin -Password pass -File C:\cred.xml

# Recall & Use

$cred = Get-VICredentialStoreItem -User admin -Host $VirtualCenterServer  -File C:\cred.xml

Connect-VIServer -Server $cred.Host -User $cred.User -Password $cred.Password | Out-Null


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
1 Reply
LucD
Leadership
Leadership
Jump to solution

The output from the New-VICredentialStoreItem is an XML file.

You can use the credenial store as follows

# Save

New-VICredentialStoreItem -Host $VirtualCenterServer  -User Admin -Password pass -File C:\cred.xml

# Recall & Use

$cred = Get-VICredentialStoreItem -User admin -Host $VirtualCenterServer  -File C:\cred.xml

Connect-VIServer -Server $cred.Host -User $cred.User -Password $cred.Password | Out-Null


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos