How can I execute scripts in a code created powershell shell that has Write-Host commands in it? -



How can I execute scripts in a code created powershell shell that has Write-Host commands in it? -

i have script writing relies on functions in imported module. script takes while due io (web requests) , parallize hundreds of thousands of iterations of script block.

after attempting several different methods (with little success due restrictions start-job , other things) current implementation relies on pre-creating pool of powershell "shells" created via $shell = [powershell]::create().

one of module methods have phone call bootstrap shell (so it's in right state) has phone call write-host in it. when phone call $shell.invoke() next error occurs:

write-host : command prompts user failed because host programme or command type not back upwards user interaction. seek host programme supports user interaction, such windows powershell console or windows powershell ise, , remove prompt-related commands command types not back upwards user interaction, such windows powershell workflows.

now, since module custom can remove write-host calls, reduces user friendliness when run straight end users. can create switch parameter not execute write-host if parameter true, downwards line bit of work (feasible, i'd rather not).

is there way can write-host not error out in scenario? don't care input in scenario, don't want errors.

the fastest way work define dummy write-host function in script, or define in runspace independently before running script.

$ps.addscript("function write-host {}").invoke() $ps.commands.clear() # can invoke scripts utilize write-host # sense free implement write-host writes log file

simple that. reason you're getting error because programmatic invocation not expect user interaction. there ways create work employs different apis.

powershell

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -