// Here is where we execute posh code
public static AttackState PSExec(AttackState attackState)
{
using (Pipeline pipeline = attackState.runspace.CreatePipeline())
{
pipeline.Commands.AddScript(attackState.cmd);
// If we're in an auto-complete loop, we want the PSObjects, not the string from the output of the command
// TODO: clean this up
if (attackState.loopType != null)
{
pipeline.Commands[0].MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output);
}
else
{
pipeline.Commands[0].MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output); pipeline.Commands.Add("out-default");
}
try
{
attackState.results = pipeline.Invoke();
}
catch (Exception e)
{
attackState.results = null;
Display.Exception(attackState, e.Message);
}
pipeline.Dispose();
}
//Clear out command so it doesn't get echo'd out to console again.
attackState.ClearIO();
if (attackState.loopType == null)
{
attackState.cmdComplete = true;
}
return(attackState);
}