Is there a way to store the password for the Commect-VIServer cmdlet in a file? I tried using the ConvertTo-SecureString cmdlet but wasn't able to get it to work.
$vpass = ConvertTo-SecureString (Get-Content C:\scripts\vpassword.txt)
Connect-VIServer -Server vc.domain.com -Protocol https -User user -Password $vpass
Thanks,
Toad
You are missing some steps.
Provided you created the file this way
$MyPswd = "xyz1234" ConvertTo-SecureString $MyPswd -AsPlainText -Force | `
ConvertFrom-SecureString | Out-File -FilePath "C:\pass.txt"
You can convert it back like this
$pswdSec = Get-Content "C:\pass.txt" | ConvertTo-SecureString
$bPswd = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pswdSec) $pswd = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bPswd) $pswd
Note that you have to create and use the password with the same account !
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You are missing some steps.
Provided you created the file this way
$MyPswd = "xyz1234" ConvertTo-SecureString $MyPswd -AsPlainText -Force | `
ConvertFrom-SecureString | Out-File -FilePath "C:\pass.txt"
You can convert it back like this
$pswdSec = Get-Content "C:\pass.txt" | ConvertTo-SecureString
$bPswd = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pswdSec) $pswd = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bPswd) $pswd
Note that you have to create and use the password with the same account !
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks much for that. It worked perfectly.
Toad