by dcoz at 2013-01-02 02:21:37
Hi Guys,by DonJ at 2013-01-02 07:38:06
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
Precede it with an escape ` character or put it in single quotes. Whichever you prefer.by dcoz at 2013-01-03 00:06:34
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.
Thank Don,by megamorf at 2013-01-03 00:53:53
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
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.by DonJ at 2013-01-03 07:53:58
http://www.vmware.com/support/developer … ation.html
Ah, sorry. I thought "$password" was the password you were using as an example.by dcoz at 2013-01-03 09:49:32
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.
Ah so simple
thanks
Guys