I'm looking to run some powershell scripts via automation. Something like:
IList errors;
Collection<PSObject> res = null;
using (RunspaceInvoke rsi = new RunspaceInvoke())
{
try
{
res = rsi.Invoke(commandline, null, out errors);
}
catch (Exception ex)
{
LastErrorMessage = ex.ToString();
Debug.WriteLine(LastErrorMessage);
return 1;
}
}
the problem I'm facing is that if my script uses cmdlets such as write-host
the above throws an System.Management.Automation.CmdletInvocationException
-
Cannot invoke this function because the current host does not implement it.
What are some good options for getting around this problem?