// Token: 0x06000E76 RID: 3702 RVA: 0x00056FB0 File Offset: 0x000551B0
        private Collection <T> RunPSCommand <T>(PSCommand command, out Collection <ErrorRecord> errors, IPublicFolderMailboxLoggerBase logger)
        {
            errors = null;
            PowerShellProxy powerShellProxy = null;
            Collection <T>  result          = AssistantRunspaceProxy.RunTimedOperation <Collection <T> >(delegate()
            {
                powerShellProxy = new PowerShellProxy(this.runspaceProxy, command);
                return(powerShellProxy.Invoke <T>());
            }, AssistantRunspaceProxy.GetCommandString(command), logger);

            if (powerShellProxy.Failed)
            {
                errors = powerShellProxy.Errors;
            }
            return(result);
        }
        public PsScriptCriterion(string scriptFile)
        {
            if (scriptFile == null)
            {
                throw new ArgumentNullException("scriptFile");
            }
            if (!File.Exists(scriptFile))
            {
                throw new FileNotFoundException("Cannot find the specified PowerShells script.", scriptFile);
            }

            // TODO: Load PS1 script and assign variables
            _script = PowerShellProxy.Create <IScript>(scriptFile);
            this.DirectorySupport = _script.SupportDirectories;
            this.FileSupport      = _script.SupportFiles;
        }
        public Collection <T> RunPSCommand <T>(PSCommand command, out ErrorRecord error)
        {
            PowerShellProxy powerShellProxy = null;
            Collection <T>  result          = AnchorUtil.RunTimedOperation <Collection <T> >(this.Context, delegate()
            {
                powerShellProxy = new PowerShellProxy(this.runspaceProxy, command);
                return(powerShellProxy.Invoke <T>());
            }, AnchorRunspaceProxy.GetCommandString(command));

            if (powerShellProxy.Failed)
            {
                error = powerShellProxy.Errors[0];
                return(null);
            }
            error = null;
            return(result);
        }
        // Token: 0x06000018 RID: 24 RVA: 0x0000252C File Offset: 0x0000072C
        internal static Collection <PSObject> ExecuteCommandsInRunspace(SmtpAddress user, PSCommand command, CultureInfo executingCulture, out string errorMessage, out string warningMessage)
        {
            Collection <PSObject> result         = null;
            StringBuilder         stringBuilder  = new StringBuilder();
            StringBuilder         stringBuilder2 = new StringBuilder();

            errorMessage   = string.Empty;
            warningMessage = string.Empty;
            IRecipientSession recipientSession = ApprovalProcessor.CreateRecipientSessionFromSmtpAddress(user);
            ADUser            aduser           = recipientSession.FindByProxyAddress(ProxyAddress.Parse((string)user)) as ADUser;

            if (aduser == null)
            {
                errorMessage = Strings.ErrorUserNotFound((string)user);
                return(null);
            }
            GenericIdentity     identity            = new GenericIdentity(aduser.Sid.ToString());
            InitialSessionState initialSessionState = null;

            try
            {
                initialSessionState = new ExchangeRunspaceConfiguration(identity).CreateInitialSessionState();
                initialSessionState.LanguageMode = PSLanguageMode.FullLanguage;
            }
            catch (CmdletAccessDeniedException)
            {
                errorMessage = Strings.ErrorNoRBACRoleAssignment((string)user);
                return(null);
            }
            CultureInfo currentCulture   = Thread.CurrentThread.CurrentCulture;
            CultureInfo currentUICulture = Thread.CurrentThread.CurrentUICulture;

            try
            {
                if (executingCulture != null)
                {
                    Thread.CurrentThread.CurrentCulture   = executingCulture;
                    Thread.CurrentThread.CurrentUICulture = executingCulture;
                }
                using (RunspaceProxy runspaceProxy = new RunspaceProxy(new RunspaceMediator(new ForestScopeRunspaceFactory(new BasicInitialSessionStateFactory(initialSessionState), new BasicPSHostFactory(typeof(RunspaceHost), true)), new EmptyRunspaceCache())))
                {
                    try
                    {
                        PowerShellProxy powerShellProxy = new PowerShellProxy(runspaceProxy, command);
                        result = powerShellProxy.Invoke <PSObject>();
                        if (powerShellProxy.Errors != null)
                        {
                            foreach (ErrorRecord errorRecord in powerShellProxy.Errors)
                            {
                                stringBuilder.Append(errorRecord.ToString());
                            }
                        }
                        if (powerShellProxy.Warnings != null)
                        {
                            foreach (WarningRecord warningRecord in powerShellProxy.Warnings)
                            {
                                stringBuilder2.Append(warningRecord.ToString());
                            }
                        }
                    }
                    catch (CmdletInvocationException)
                    {
                        stringBuilder.Append(Strings.ErrorTaskInvocationFailed((string)user).ToString(executingCulture));
                    }
                    catch (ParameterBindingException)
                    {
                        stringBuilder.Append(Strings.ErrorTaskInvocationFailed((string)user).ToString(executingCulture));
                    }
                    catch (CommandNotFoundException)
                    {
                        stringBuilder.Append(Strings.ErrorTaskInvocationFailed((string)user).ToString(executingCulture));
                    }
                    catch (RuntimeException)
                    {
                        stringBuilder.Append(Strings.ErrorTaskInvocationFailed((string)user).ToString(executingCulture));
                    }
                    finally
                    {
                        errorMessage   = stringBuilder.ToString();
                        warningMessage = stringBuilder2.ToString();
                    }
                }
            }
            finally
            {
                if (executingCulture != null)
                {
                    Thread.CurrentThread.CurrentCulture   = currentCulture;
                    Thread.CurrentThread.CurrentUICulture = currentUICulture;
                }
            }
            return(result);
        }