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));
 }
Exemplo n.º 2
0
        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
                       ));
        }
Exemplo n.º 3
0
        } // end ProcessRecord()

        internal static Collection <PSObject> InvokeScript(CommandInvocationIntrinsics invokeCommand,
                                                           ScriptBlock scriptBlock,
                                                           bool useNewChildScope)
        {
            return(invokeCommand.InvokeScript(useNewChildScope,
                                              scriptBlock,
                                              null,
                                              null));
        } // end InvokeScript
Exemplo n.º 4
0
 public static IEnumerable <T> RunScript <T>(CommandInvocationIntrinsics cii, string script)
 => cii.InvokeScript(script).Select(o => o?.BaseObject).Where(o => o != null).OfType <T>();