Help needed to automate console output.

Ask your PowerShell-related questions, including questions on cmdlet development!
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.
Locked
rfadnavis002
Posts: 2
Last visit: Thu Apr 01, 2021 11:03 pm

Help needed to automate console output.

Post by rfadnavis002 »

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.

jvierra
Posts: 14930
Last visit: Mon Sep 20, 2021 8:13 am
Answers: 14
Has voted: 3 times
Been upvoted: 11 times

Re: Help needed to automate console output.

Post by jvierra »

That would depend on how the script is written.

Try using the redirector to send the password.

User avatar
ecorreale
Posts: 6
Last visit: Fri Apr 02, 2021 12:14 pm
Has voted: 1 time

Re: Help needed to automate console output.

Post by ecorreale »

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

  1.  
  2. # Define clear text string for username and password
  3. [string]$userName = 'MyUserName'
  4. [string]$userPassword = 'MySuperSecurePassword'
  5.  
  6. # Convert to SecureString
  7. [securestring]$secStringPassword = ConvertTo-SecureString $userPassword -AsPlainText -Force
  8. [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
  1. $myCredentials = Get-Credential
  2. $myCredentials | Export-Clixml -path .\MyScriptInput.xml
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. [PSCredential]$creds = Import-Clixml -Path .\MyScriptInput.xml

jvierra
Posts: 14930
Last visit: Mon Sep 20, 2021 8:13 am
Answers: 14
Has voted: 3 times
Been upvoted: 11 times

Re: Help needed to automate console output.

Post by jvierra »

My take is that the script in the EXE is VBScript. Although the question may be speculative then the Alex's PS solution would be the best approach.

Locked