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 h
Try changing your WMF version to 5.1 - https://www.microsoft.com/en-us/download/details.aspx?id=54616
The fastest way to get this to work is to define a dummy write-host
function in your script, or to simply define it in the runspace independently before running your script.
$ps.addscript("function write-host {}").invoke()
$ps.commands.clear()
# now you can invoke scripts that use write-host
# feel free to implement a write-host that writes to a log file
Simple as that. The reason you're getting that error is because programmatic invocation like that does not expect user interaction. There are ways to make this work but it employs different APIs.
If you need the output, you can use:
$ps.addscript("function write-host($out) {write-output $out}").invoke()
$ps.commands.clear()