I have code running a powershell Script though the use of the System.Management.Automation
namespace in C#, similar to the code below.
using (mPowershell = PowerShell.Create())
{
mPowershell.AddScript(GetScriptText(mStep), true);
SetPowershellVariables(mPowershell);
output = new PSDataCollection<PSObject>();
output.DataAdded += new EventHandler<DataAddedEventArgs>(Output_DataAdded);
mPowershell.InvocationStateChanged += new EventHandler<PSInvocationStateChangedEventArgs>(Powershell_InvocationStateChanged);
IAsyncResult asyncResult = mPowershell.BeginInvoke<PSObject, PSObject>(null, output);
}
As expected I am getting errors, and I would like to debug them.
Is there a way, without going into the powershell script and putting a Write-Host $somevariable
every 2 lines, to step by step debug this script?
I should mention the script itself cannot run standalone, the C# code adds variables to the runspace of the script.