Issue when using -AsSecureString cmdlet

Welcome Forums General PowerShell Q&A Issue when using -AsSecureString cmdlet

This topic contains 1 reply, has 1 voice, and was last updated by

1 year, 6 months ago.

  • Author
  • #73975

    Points: 0
    Rank: Member

    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 –> (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?

  • #73976

    Points: 0
    Rank: Member

    Found a way!

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

    This seems to work alright...


The topic ‘Issue when using -AsSecureString cmdlet’ is closed to new replies.