I am using the following script to pass SQL credentials at the command line , but I need user to enter the password for the SQL user not the Windows Credentials in it and to make sure that the password is not revealed in clear text when inserted in the prompt. Here is my script:
Param(
[Parameter(Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[string]$dbusername="",
[Parameter(Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[string]$password="",
[Parameter(Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[string]$Machine=""
)
This works fine, but I would like to make sure that the password is hidden when user is inserting it in the prompt.
I have used this line to do it
Read-Host -Prompt "Enter your password" -AsSecureString
But this cannot be inserted in the Param block, and I I insert it afterwards it has no effect.
How can I mask the password when is inserted by the user at the prompt?
[securestring]$password=""should be suffisant[Parameter(Mandatory)][System.Management.Automation.Credential()][PSCredential]$Credential