Creating a PowerShell script that calls an apps cmdlet. When then cmdlet runs it prompts for a response and the scripts hangs. The cmdlet doesn't have any parameters for this. Is there any way to respond programmatically? I tried ECHO but that doesn't work.
The only way to get PowerShell scripts that solicit input via the host - typically, via
Read-Host
- to read input from the pipeline instead of from the keyboard is to use to run the script as an external PowerShell instance.A simple example:
Note: Running the script / command via an external PowerShell instance comes at a cost:
Creating a new PowerShell process is costly in terms of performance.
Output from the new instance will be textual (strings) by default, not objects.
-OutputFormat xml
to the external instance and post-processing the results viaImport-CliXml
, but that has limitations.