I have a script that I am writing which relies on functions in an imported module. This script takes a while due to IO (web requests) and I would like to parallize it for hundreds of thousands of iterations of a script block.
After attempting several different methods (with little success due to restrictions with Start-Job
and other things) the current implementation relies on pre-creating a pool of powershell "shells" created via $shell = [Powershell]::Create()
.
One of the module methods I have to call to bootstrap the shell (so it's in a correct state) has a call to Write-Host
in it. When I call $shell.Invoke()
the following error occurs:
Write-Host : A command that prompts the user failed because the host program or the command type does not support user interaction. Try a host program that supports user interaction, such as the Windows PowerShell Console or Windows PowerShell ISE, and remove prompt-related commands from command types that do not support user interaction, such as Windows PowerShell workflows.
Now, since the module is custom I can remove the Write-Host
calls, but that reduces user friendliness when it is run directly by end users. I can create a switch
parameter that does not execute Write-Host if the parameter is true, but to do that down the line is a good bit of work (feasible, but I'd rather not).
Is there any way I can get Write-Host
to not error out in this scenario? I don't actually care about the input in this scenario, I just don't want the errors.