Skip to content

Instantly share code, notes, and snippets.

@ob1-sc
Created May 9, 2018 18:12
Show Gist options
  • Save ob1-sc/14c31ea218794d46ea8d13be294eea47 to your computer and use it in GitHub Desktop.
Save ob1-sc/14c31ea218794d46ea8d13be294eea47 to your computer and use it in GitHub Desktop.
Accept masked input from bat script
@echo off
set "psCommand=powershell -Command "$pword = read-host 'Enter Password' -AsSecureString ; ^
$BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /f "usebackq delims=" %%p in (`%psCommand%`) do set password=%%p
echo %password%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment