0

I have a powershell script that would like user to enter password. It calls a function to get a pop up box for the user input. Now it is in plaintext. I'd like it to be hidden/masked

This is the function created :---

function Read-InputBoxDialog([string]$Message, [string]$WindowTitle, [string]$DefaultText)
{
    Add-Type -AssemblyName Microsoft.VisualBasic
    return [Microsoft.VisualBasic.Interaction]::InputBox($Message, $WindowTitle, $DefaultText)
}

This is the way i called the function from powershell : ---

$SQLPassword = Read-InputBoxDialog -Message "Please enter SQL password used to connect to Database Server" -WindowTitle "Sql Server Authentication" -DefaultText "" 

How do I ask mask the password as **** ?

Ely
  • 3
  • 3
  • possible duplicate of [Prompt for user input In PowerShell](http://stackoverflow.com/questions/8184167/prompt-for-user-input-in-powershell) – vonPryz Mar 11 '15 at 06:11
  • This can't be done with an input box: http://msdn.microsoft.com/en-us/library/Aa164894 – David Brabant Mar 11 '15 at 07:35

1 Answers1

2

Instead of an input box, Powershell has got its own implementation Get-Credential. It stores credentials as secure strings, so getting a plaintext password requires some tweaking. Like so,

$cred = Get-Credential -Message "Enter Sql password"
$cred.GetNetworkCredential().username # Show the username
$cred.GetNetworkCredential().password # Show the password
vonPryz
  • 22,996
  • 7
  • 54
  • 65