public IEnumerable <PSObject> InvokeCaptureOutput(CommandInfo commandInfo, Hashtable args) { if (commandInfo == null) { throw new ArgumentNullException("commandInfo"); } return(_invokeCommand.InvokeScript("param($c, $a) return . $c @a", true, PipelineResultTypes.None, null, commandInfo, args)); }
public static Collection <PSObject> InvokeRestCommand( this CommandInvocationIntrinsics commandInvocation, Uri uri, WebRequestMethod method, object body, IDictionary headers ) { var powershellParams = new Dictionary <object, object> { { nameof(uri), uri }, { nameof(method), method }, { nameof(body), body }, { nameof(headers), headers } }; var paramString = GeneralUtils.FormatPowerShellParams(powershellParams); var scriptBlock = $"Invoke-RestMethod {paramString}"; return(commandInvocation.InvokeScript( scriptBlock, false, System.Management.Automation.Runspaces.PipelineResultTypes.Output, null, null )); }
} // end ProcessRecord() internal static Collection <PSObject> InvokeScript(CommandInvocationIntrinsics invokeCommand, ScriptBlock scriptBlock, bool useNewChildScope) { return(invokeCommand.InvokeScript(useNewChildScope, scriptBlock, null, null)); } // end InvokeScript
public static IEnumerable <T> RunScript <T>(CommandInvocationIntrinsics cii, string script) => cii.InvokeScript(script).Select(o => o?.BaseObject).Where(o => o != null).OfType <T>();