Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

secure password input while handling special characters

$
0
0

Hello,

I am trying to create a bat file to allow password input at the command prompt.  I use powershell with the following command:

:: =============================================================================================
:: Get Password - hide from the screen
:: =============================================================================================
SETLOCAL DISABLEDELAYEDEXPANSION
SET "psCommand=powershell -Command "$pword = read-host 'password' -AsSecureString ; ^
    $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^
        -join("0",[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR))""
for /f "usebackq delims=" %%p in (`%psCommand%`) do set D_PASSWORD=%%p
SETLOCAL ENABLEDELAYEDEXPANSION
SET D_PASSWORD=!D_PASSWORD:~1!

:: =============================================================================================

This works great for all but the exclamation mark (!) character

How can I fix my script to take this character?

Thanks!


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>