Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, January 8, 2019 2:52 AM
Hi Experts,
I am trying to use encrypted password file to login to VMware Vcenter but unable to do so. Could you please point me where I am doing wrong? Thank you very much for the help.
Connect-VIServer : 8/01/2019 3:37:08 p.m. Connect-VIServer Cannot complete login due to an incorrect username or password.
+ CategoryInfo : NotSpecified: (:) [Connect-VIServer], InvalidLogin
$credential = Get-Credential
$credential.Password | ConvertFrom-SecureString | Set-Content c:\temp\password.txt
################################
add-pssnapin VMware.VimAutomation.Core
$EncryptedPW = Get-Content "C:\temp\password.txt"
$SecureString = ConvertTo-SecureString -String $EncryptedPW
Connect-VIServer -Server servername -user "domain\user_name" -password $SecureString
Get-VM | Get-Snapshot | Where {$_.Created -lt (Get-Date).AddDays(-3)}
All replies (4)
Wednesday, January 9, 2019 1:22 AM ✅Answered
Thank you Lee and JRV,
I was able to sort this out as below.
# On-time script to generate the password file
GET-CREDENTIAL –Credential (Get-Credential) | EXPORT-CLIXML "C:\temp\SecureCredentials.xml"
# Below script can be scheduled using task scheduler
add-pssnapin VMware.VimAutomation.Core
$Credentials = IMPORT-CLIXML "C:\temp\SecureCredentials.xml"
$vCenterServer = "Vmware_server"
connect-viserver -Server $vCenterServer -Credential $Credentials
$temp = Get-VM | Get-Snapshot | Where {$_.Created -lt (Get-Date).AddDays(-3) } | Select-Object VM, Name, Created
$temp = $temp | Out-String
Write-output "$temp"
Tuesday, January 8, 2019 7:01 AM
Hi,
Thanks for your question.
I don't think anything wrong with your code. You may need to check the error message "Cannot complete login due to an incorrect username or password". check your username and password.
the variable with security password is useful for me.
Also, you can just use the code below to mask your password.
$security=Read-Host "enter your password" -AsSecureString
Best Regards,
Lee
Just do it.
Tuesday, January 8, 2019 7:08 AM
$credential = Get-Credential
Connect-VIServer -Serverservername -Credential $credential
\(ツ)_/
Wednesday, January 9, 2019 1:49 AM
Hi,
I am glad to hear that your issue was successfully resolved. If there is anything else we can do for you, please feel free to post in the forum. Please mark your answer.
Best Regards,
Lee
Just do it.