public void Invoke(string command, params string[] arguments)
        {
            var p = PowerShell.Create();
            p.Runspace.SessionStateProxy.SetVariable("request", _request);
            p.AddScript(_request.HelperModuleText,false);
            p.AddScript(command);
            foreach (var result in p.Invoke()) {
                // dunno what to do with the result yet.

            }
            p.Dispose();
            p = null;

            using (dynamic ps = new DynamicPowershell()) {
                // grant access to the current call request.
                ps["request"] = _request;

                // import our new helpers
                DynamicPowershellResult result = ps.ImportModule(Name: _request.HelperModulePath, PassThru: true);
                if (!result.Success) {
                    throw new Exception("Unable to load helper module for install script.");
                }

                result = ps.InvokeExpression(command);

                if (!result.Success) {
                    foreach (var i in result.Errors) {
                        _request.Error(i.CategoryInfo.Reason, i.Exception.Message, null);
                    }
                    throw new Exception("Failed executing chocolatey script.");
                }

                ps["request"] = null;
            }
        }
Esempio n. 2
0
        public void Invoke(string command, params string[] arguments)
        {
            var p = PowerShell.Create();

            p.Runspace.SessionStateProxy.SetVariable("request", _request);
            p.AddScript(_request.HelperModuleText, false);
            p.AddScript(command);
            foreach (var result in p.Invoke())
            {
                // dunno what to do with the result yet.
            }
            p.Dispose();
            p = null;


            using (dynamic ps = new DynamicPowershell()) {
                // grant access to the current call request.
                ps["request"] = _request;

                // import our new helpers
                DynamicPowershellResult result = ps.ImportModule(Name: _request.HelperModulePath, PassThru: true);
                if (!result.Success)
                {
                    throw new Exception("Unable to load helper module for install script.");
                }

                result = ps.InvokeExpression(command);

                if (!result.Success)
                {
                    foreach (var i in result.Errors)
                    {
                        _request.Error(i.CategoryInfo.Reason, i.Exception.Message, null);
                    }
                    throw new Exception("Failed executing chocolatey script.");
                }

                ps["request"] = null;
            }
        }