I am trying to use a script to change all the root passwords on our ESXi servers, but our root password has a ! in it and this causes the script to fail.
This is the line in the script where the user inputs the pasword :
$rootpswd = Read-Host -Prompt "Old root password"
How do I change the script so that it will accept the ! in the password?
Thanks
Marc Crawford
I should have been more specific, I didn't mean single quotes around the Read-Host prompt.
When you use an exclamation mark as the 1st character in a string you pass to the Read-Host cmdlet, youwill have to put the exclamation mark twice. Otherwise you stumble upon this feature.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try using single quotes instead of double quotes
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
So I changed it to
$rootpswd = Read-Host -Prompt 'Old root password'
And that did not work either.
As a tempory fix for the script, I just hard coded the password like this and it worked.
$rootpswd = '!QAZxsw2'
But I don't want to hard code the password. I want to prompt the user for the password.
#06:31:15> $a=read-host
!QAZxsw2
#06:31:36> $a
!QAZxsw2
Or while authenticating : $a=get-credential, it should work.
Greg
I should have been more specific, I didn't mean single quotes around the Read-Host prompt.
When you use an exclamation mark as the 1st character in a string you pass to the Read-Host cmdlet, youwill have to put the exclamation mark twice. Otherwise you stumble upon this feature.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Awesome! Thanks LucD