Issue when using -AsSecureString cmdlet

Hi Guys,

I am facing a very odd issue, I have a script which prompt for the user password and checks if the password is complex or not depending on some criteria I have set. Below is the script block that i am using

 $username = read-host "Please enter your username"
 $password = read-host "Please enter the password you want to test" -AsSecureString 

So i enter the password as –> powershell.com (just to test)

As per the criteria I get there is an upper case in the password.

But when I remove the -asSecureString parameter, and enter the same password. it seems to pass the check properly.

Does using -AsSecureString change anything while storing the password?

Found a way!

$password = read-host -assecurestring
$decodedpassword =[System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password)) 

This seems to work alright…

-A