This topic contains 2 replies, has 2 voices, and was last updated by  Dave S December 13, 2018.

Zerto scripts using encrypted passwords automation

  • For the life of me I can not get these Zerto scripts to run with a password file that I have created using ConvertTo-SecureString commands listed here per Zerto scripting reference doc… https://www.pdq.com/blog/secure-password-with-powershell-encrypting-credentials-part-1/

    “SecretPassword” | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Out-File “C:\support\zerto\scripts\zertpass.txt”

    I then call this zertpass.txt file using…

    $ZertoPassword = Get-Content “C:\support\zerto\scripts\zertpass.txt” | ConvertTo-SecureString

    So the beginning of my script with setting variables looks like this…

    # Script variables
    $ZertoServer = “192.168.0.1”
    $ZertoPort = “9669”
    $ZertoUser = “zertouser”
    $ZertoPassword = Get-Content “C:\support\zerto\scripts\zertpass.txt” | ConvertTo-SecureString

    When I run the script I get the {“Message”:”Failed logging in to vcenter with username zertouser. Error was ‘Cannot complete
    login due to an incorrect user name or password.'”} error.  If I just put in the password in plain text like this.

    $ZertoPassword = “SecretPassword”  – The script works just fine.  What am I missing.  I am trying to run this script…

    Getting a List of VMs by VPG

    PLEASE HELP.

     

    Hi Dave,

    It looks like you are trying to pass a SecureString to a plain text password field.  Try this code to convert the SecureString to a plain text password for use with the API.

    “SecretPassword” | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Out-File “C:\support\zerto\scripts\zertpass.txt”
    $SecurePassword = Get-Content “C:\support\zerto\scripts\zertpass.txt” | ConvertTo-SecureString
    $bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword)
    $ZertoPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr)

    Thank you Tim!  This did work.  I was assuming that the script would accept the SecureString in the password field not knowing that it was a plain text password field.

    Thanks.

You must be logged in to create new topics. Click here to login