Would you like to: [1] Accept the certificate for this session Please input your selection (The default selection is [1]): 1 I have to enter number one here, how it can be done through power shell script
Asked
Active
Viewed 834 times
-1
-
Possible duplicate of [Powershell - Interact with executable's command line prompts?](https://stackoverflow.com/questions/43852056/powershell-interact-with-executables-command-line-prompts) – BenH Jun 27 '17 at 14:26
1 Answers
0
Read-Host
would be the way to do it from the console while using Write-Host/Write-Output to present the option information. You would of course need to check the contents of the variable to see if you got an expected result.
If you're looking for a simple yes/no answer and are OK with popups, use a .NET messagebox:
[System.Windows.Forms.MessageBox]::Show('message', 'titlemessage')
There are tons of overloads for this which include giving you the ability to control the buttons displayed and the icon (warning, error, informational, etc.)
EDIT: This SO post shows how to accomplish SendKeys functionality with both a COM object and a .NET object: How to perform keystroke inside powershell?
$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate('title of the application window')
Sleep 1
$wshell.SendKeys(1)
and
add-type -AssemblyName System.Windows.Forms
[System.Windows.Forms.SendKeys]::SendWait(1)
or
add-type -AssemblyName microsoft.VisualBasic
add-type -AssemblyName System.Windows.Forms
[Microsoft.VisualBasic.Interaction]::AppActivate(“Calc”)
[System.Windows.Forms.SendKeys]::SendWait(“1{ADD}1=”)

thepip3r
- 2,855
- 6
- 32
- 38
-
1I believe he is not asking for the script to prompt for that information, but for the script to input that information into an executable. – BenH Jun 27 '17 at 14:28
-
Ah yes... I see that now. He wants to interact with a prompt. see edit. – thepip3r Jun 27 '17 at 14:29