VMware Cloud Community
crawfordm
Expert
Expert
Jump to solution

Special Character in the input

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

------------------------------------------------------------------ If you found this answer useful please consider the use of the Helpful or Correct buttons to award points. Thanks, Marc Crawford CCNA, MCSE, MCTS, A+, Net+, Sec +, VCA-WM, VCA-DCV, VCA-Cloud, VCA-NV, VCP-NV, VCP-DCV, VCP, VCAP5-DCA http://gplus.to/marccrawford http://blog.marccrawford.com @uber_tech_geek
Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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.

read-host-feature.png


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

Try using single quotes instead of double quotes


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

crawfordm
Expert
Expert
Jump to solution

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.

------------------------------------------------------------------ If you found this answer useful please consider the use of the Helpful or Correct buttons to award points. Thanks, Marc Crawford CCNA, MCSE, MCTS, A+, Net+, Sec +, VCA-WM, VCA-DCV, VCA-Cloud, VCA-NV, VCP-NV, VCP-DCV, VCP, VCAP5-DCA http://gplus.to/marccrawford http://blog.marccrawford.com @uber_tech_geek
Reply
0 Kudos
Grzesiekk
Expert
Expert
Jump to solution

#06:31:15> $a=read-host
!QAZxsw2
#06:31:36> $a
!QAZxsw2

Or while authenticating : $a=get-credential, it should work.

Greg

--- @blog https://grzegorzkulikowski.info
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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.

read-host-feature.png


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
crawfordm
Expert
Expert
Jump to solution

Awesome!  Thanks LucD

------------------------------------------------------------------ If you found this answer useful please consider the use of the Helpful or Correct buttons to award points. Thanks, Marc Crawford CCNA, MCSE, MCTS, A+, Net+, Sec +, VCA-WM, VCA-DCV, VCA-Cloud, VCA-NV, VCP-NV, VCP-DCV, VCP, VCAP5-DCA http://gplus.to/marccrawford http://blog.marccrawford.com @uber_tech_geek
Reply
0 Kudos