dealing with dollar symbol within secure string password

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 3 months ago.

  • Author
    Posts
  • #5391

    by dcoz at 2013-01-02 02:21:37

    Hi Guys,
    I am wondering how to deal with the dollar symbol within a secure string.
    I have a basic script that does the below

    username = read-Host "Please enter Username"
    $password = Read-Host -Prompt "Please enter Password?" -AsSecureString
    $VMHost | Get-VMHostAuthentication | Set-VMHostAuthentication -JoinDomain -Domain test.com -Username "$username" -Password "$password"

    The password i am entering has a dollar sign but the script errors out with the message of incorrect login.

    Any help would be great

    Thanks

    Dougie

    by DonJ at 2013-01-02 07:38:06

    Precede it with an escape ` character or put it in single quotes. Whichever you prefer.

    In double quotes, PowerShell is seeing $password as a variable and attempting to replace it with the variable's contents. It won't do that in single quotes.

    by dcoz at 2013-01-03 00:06:34

    Thank Don,
    Just to be clear are you meaning when prompted to enter your password enter it in the prompt box with single quotes or escape character or change the code to the below?
    username = read-Host "Please enter Username"
    $password = Read-Host -Prompt "Please enter Password?" -AsSecureString
    $VMHost | Get-VMHostAuthentication | Set-VMHostAuthentication -JoinDomain -Domain test.com -Username "$username" -Password '$password'

    If I put the variable in single quotes wouldn't this just take the -password parameter as a literal string?

    Tks
    Dougie

    by megamorf at 2013-01-03 00:53:53

    Don Jones told you to remove the quotation marks around the variables. These tell powershell to expand your variables and you don't want that when you pass variables as arguments.

    http://www.vmware.com/support/developer ... ation.html

    by DonJ at 2013-01-03 07:53:58

    Ah, sorry. I thought "$password" was the password you were using as an example.

    The correct syntax in your case would be


    -Username $username -Password $password

    There's no need to use any quotes at all. If that isn't working, and your password contains a $, then the problem isn't with PowerShell, it's with the cmdlet.

    by dcoz at 2013-01-03 09:49:32

    Ah so simple 🙂
    thanks
    Guys

You must be logged in to reply to this topic.