The running script has read-host
in it which requires input by design. There are not really any pretty ways around it short of using sendkeys or third party apps like AutoHotKey. Only thing I could think is to surpress Read-Host by running PowerShell in non-interactive mode which
Does not present an interactive prompt to the user.
That has a side effect where an error will be triggered. Consider the following script.
$var = "Original"
$result = read-host -Prompt "Push Enter or type and such"
if($result){$var=$result}
$var
Set a variable to a string value and prompt the user to change it. Display the results whether the user enters null or nothing.
Now run that in noninteractive mode...
PS D:\Temp\PSH> powershell.exe -Noninteractive -file .\skipReadHost.ps1
powershell.exe : read-host : Windows PowerShell is in NonInteractive mode. Read and Prompt
At line:1 char:1
+ powershell.exe -Noninteractive -file .\skipReadHost.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (read-host : Win...ead and Prompt :String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
functionality is not available.
At D:\Temp\PSH\skipReadHost.ps1:2 char:11
+ $result = read-host -Prompt "Push Enter or type and such"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Read-Host], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.ReadHostCommand
Original
Notice at the end the string came out with its first state. This all depends on how the script handles this prompt being skipped.
From the looks of it you could also just remove the read-host
logic from the script and avoid this issue altogether.