I am searching to operate some powershell scripts via automation. Something similar to:
IList errors Collection<PSObject> res = null using (RunspaceInvoke rsi = new RunspaceInvoke()) catch (Exception ex)
the issue I am facing is when my script uses cmdlets for example
write-host the above mentioned throws an
Cannot invoke this function because the present host doesn't implement it.
What exactly are good quality choices for making your way around this issue?
One choice is to produce a write-host function and inject that to your runspace. The function will require priority on the cmdlet with similar title. Within this function, you can do nothing at all or possibly use [console]::writeline() in case your application is really a console application, or in case your application is really a GUI application, inject some object in to the PowerShell session the function can write the output to (take a look at Runspace.SessionStateProxy.SetVariable).
Another (little more complicated) choice is to implement the PowerShell hosting connects inside your application.