I will create a script to connection to vSphere, and the script will sent to user to use.
I don't want to show password in the script.
What should I do?
You can use the VICredentialStore:
New-VICredentialStoreItem -User <user> -Password <user> -Host <server> -File C:\<your location.xml>
$user =Get-VICredentialStoreItem -File C:\<your location.xml> -host <server>
Connect-VIServer -Server <server> -user $user.User -password $user.Password
OR:
$Cred = Get-Credential
Connect-VIServer <your_server> -Credential $Cred
You can use the VICredentialStore:
New-VICredentialStoreItem -User <user> -Password <user> -Host <server> -File C:\<your location.xml>
$user =Get-VICredentialStoreItem -File C:\<your location.xml> -host <server>
Connect-VIServer -Server <server> -user $user.User -password $user.Password
OR:
$Cred = Get-Credential
Connect-VIServer <your_server> -Credential $Cred
Moderator: Moved to PowerCLI
I want to will the user and password file store with the script.
so, i changed the script:
$user =Get-VICredentialStoreItem -File user_and_password.xml -host <server>
Connect-VIServer -Server <server> -user $user.User -password $user.Password
but, it's failed.
Get-VICredentialStoreItem : Cannot bind parameter 'File' to the target. Exception setting "File": "Credentials file doesn't exist."
if i use "$user =Get-VICredentialStoreItem -File C:\<your location.xml> -host <server>", that is OK.
You have to provide the full path of the location
Thanks!
I have solved this problem.
I have use $PSScriptRoot arguments
$user =Get-VICredentialStoreItem -File $PSScriptRoot\vCenterPassword.xml -host corevcsvr01.sh.dto
Connect-VIServer -Server corevcsvr01.sh.dto -user $user.User -password $user.Password