Hello,
Below is my command to perform one activity. It accepts few arguments which is fine and no issues there. But when we run that command in cmd, it asks for password and confirm password.
I want to automate that password and confirm password part. How can I do that?
Example:
When we run below command in cmd -
c:\Test\myscript.exe --arg1 --arg2 --config "c:\Temp\config.cfg" --confirm
It shows below in same command prompt-
Performing the script execution for ABCD.
Enter password:
Type again to confirm:
What I need is, How can I automate this enetering of password and confirm password, considering I have the password.
Please help here. Powershell or vbscript is preferred solution.
Help needed to automate console output.
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
-
- Posts: 2
- Last visit: Thu Apr 01, 2021 11:03 pm
Re: Help needed to automate console output.
If you are asking for a way to provide the U/P to the script without having to type it, there are a couple of options.
1. Using plain Text password embedded in script
2. Use an encrypted string stored in a file
This option exports the encrypted credentials to a text file and re-imports them into the script when needed. The downside is the decryption only works on the machine where the export was created. If you are running this on more than one computer, each computer will need its own credentials file.
From a PowerShell console, execute the following commands
This prompts you for a U/P. Then, it encrypts and exports $myCredential to a file that can be used as input for your script
Inside the script, run the following to load the credentials
This imports the xml as a valid credential for use in authentication. If the password needs to change, simply re-run the export process above.
1. Using plain Text password embedded in script
- # Define clear text string for username and password
- [string]$userName = 'MyUserName'
- [string]$userPassword = 'MySuperSecurePassword'
- # Convert to SecureString
- [securestring]$secStringPassword = ConvertTo-SecureString $userPassword -AsPlainText -Force
- [pscredential]$Creds = New-Object System.Management.Automation.PSCredential ($userName, $secStringPassword)
2. Use an encrypted string stored in a file
This option exports the encrypted credentials to a text file and re-imports them into the script when needed. The downside is the decryption only works on the machine where the export was created. If you are running this on more than one computer, each computer will need its own credentials file.
From a PowerShell console, execute the following commands
This prompts you for a U/P. Then, it encrypts and exports $myCredential to a file that can be used as input for your script
- $myCredentials = Get-Credential
- $myCredentials | Export-Clixml -path .\MyScriptInput.xml
This imports the xml as a valid credential for use in authentication. If the password needs to change, simply re-run the export process above.
- [PSCredential]$creds = Import-Clixml -Path .\MyScriptInput.xml