0

I have a PowerShell script ex1.ps1 which takes user inputs and ex1.ps1 has commands to open a new PowerShell to execute an exe file:

Start-Process -FilePath "$PSHOME\powershell.exe" -ArgumentList "-command C:\APPLICATION1.exe`

I want to execute ex1.ps1 on a remote host. I am trying to call ex1.ps1 using Ansible-playbook as:

# ansible-playbook script
- name: Run basic PowerShell script
    win_powershell:
       script: |
           powershell.exe -ExecutionPolicy ByPass -File C:/Users/ex1.ps1

It is executing fine but in remote host there is no PowerShell prompt open to get the inputs.

codewario
  • 19,553
  • 20
  • 90
  • 159
  • 2
    Please edit your question and format your code correctly using the formatting aids on top of the editor window and the help on the right side of the screen. Thanks. – Zeitounator Sep 07 '21 at 05:59

1 Answers1

0

You shouldn't be expecting manual input when deploying with a tool like Ansible. I don't know the actual program you are trying to run but the best solution here is to figure out the required parameters for the program to install/start/run without user interaction.

If you are able to provide the name of the program (and it's not something internal to your organization) a more complete answer may be able to be provided.


Unrelated to your question, unless you've over-generalized your code for this question there isn't a reason to call powershell.exe from within PowerShell just to run an executable. You can either use Start-Process or the call operator & directly with the exe path in question.

I have an answer here that goes over Start-Process and the usage of & in a bit more detail.

codewario
  • 19,553
  • 20
  • 90
  • 159