/// <summary>
        /// Führt ein PS Skript aus und liefert die dabei aufgetretenen Fehler und
        /// in die Pipeline geschriebene Objekte.
        /// </summary>
        protected ExecutionResult RunScript(string script,
                                            Func <string, string> promptForValueFunc   = null,
                                            Dictionary <string, object> variables      = null,
                                            PromptForPasswordHandler promptForPassword = null)
        {
            HostCommunicationAdapter communicationAdapter = new HostCommunicationAdapter()
            {
                OnPromptForValue    = promptForValueFunc,
                OnPromptForPassword = promptForPassword
            };

            var executer = new ScriptExecuter
            {
                CommunicationAdapter = communicationAdapter,
                Variables            = variables
            };

            if (_assemblyToTest != null)
            {
                executer.Assemblies = new List <Assembly>(new[] { _assemblyToTest });
            }



            return(executer.Execute(script));
        }
示例#2
0
        /// <summary>
        /// Führt ein PS Skript aus und liefert die dabei aufgetretenen Fehler und
        /// in die Pipeline geschriebene Objekte.
        /// </summary>
        /// <param name="script"></param>
        /// <returns></returns>
        protected ExecutionResult RunScriptSecured(string script)
        {
            PermissionSet permissions = new PermissionSet(PermissionState.Unrestricted);

            AppDomain securedDomain = AppDomain.CreateDomain("script execution", null,
                                                             new AppDomainSetup
            {
                ApplicationName = "script execute",
                ApplicationBase = Path.GetDirectoryName(new Uri(this.GetType().Assembly.CodeBase).LocalPath),
            },
                                                             permissions);

            var assemblyname = typeof(ScriptExecuter).Assembly.FullName;

            ScriptExecuter executionproxy = securedDomain.CreateInstanceAndUnwrap(assemblyname, typeof(ScriptExecuter).FullName) as ScriptExecuter;

            ExecutionResult result = executionproxy.Execute(script);

            AppDomain.Unload(securedDomain);

            return(result);
        }