当前位置: 首页>>代码示例>>C#>>正文


C# Runspace.CreatePipeline方法代码示例

本文整理汇总了C#中System.Management.Automation.Runspaces.Runspace.CreatePipeline方法的典型用法代码示例。如果您正苦于以下问题:C# Runspace.CreatePipeline方法的具体用法?C# Runspace.CreatePipeline怎么用?C# Runspace.CreatePipeline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Management.Automation.Runspaces.Runspace的用法示例。


在下文中一共展示了Runspace.CreatePipeline方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PSTestScope

        public PSTestScope(bool connect = true)
        {
            SiteUrl = ConfigurationManager.AppSettings["SPODevSiteUrl"];
            CredentialManagerEntry = ConfigurationManager.AppSettings["SPOCredentialManagerLabel"];

            var iss = InitialSessionState.CreateDefault();
            if (connect)
            {
                SessionStateCmdletEntry ssce = new SessionStateCmdletEntry("Connect-SPOnline", typeof(ConnectSPOnline), null);

                iss.Commands.Add(ssce);
            }
            _runSpace = RunspaceFactory.CreateRunspace(iss);

            _runSpace.Open();

            if (connect)
            {
                var pipeLine = _runSpace.CreatePipeline();
                Command cmd = new Command("connect-sponline");
                cmd.Parameters.Add("Url", SiteUrl);
                if (!string.IsNullOrEmpty(CredentialManagerEntry))
                {
                    cmd.Parameters.Add("Credentials", CredentialManagerEntry);
                }
                pipeLine.Commands.Add(cmd);
                pipeLine.Invoke();
            }
        }
开发者ID:JohnGoldsmith,项目名称:PnP-PowerShell,代码行数:29,代码来源:PSTestScope.cs

示例2: PSTestScope

        public PSTestScope(bool connect = true)
        {
            SiteUrl = ConfigurationManager.AppSettings["SPODevSiteUrl"];
            CredentialManagerEntry = ConfigurationManager.AppSettings["SPOCredentialManagerLabel"];
            Realm = ConfigurationManager.AppSettings["Realm"];
            AppId = ConfigurationManager.AppSettings["AppId"];
            AppSecret = ConfigurationManager.AppSettings["AppSecret"];

            var iss = InitialSessionState.CreateDefault();
            if (connect)
            {
                SessionStateCmdletEntry ssce = new SessionStateCmdletEntry("Connect-PnPOnline", typeof(ConnectOnline), null);

                iss.Commands.Add(ssce);
            }
            _runSpace = RunspaceFactory.CreateRunspace(iss);

            _runSpace.Open();

            // Sets the execution policy to unrestricted. Requires Visual Studio to run in elevated mode.
            var pipeLine = _runSpace.CreatePipeline();
            Command cmd = new Command("Set-ExecutionPolicy");
            cmd.Parameters.Add("ExecutionPolicy", "Unrestricted");
            cmd.Parameters.Add("Scope", "Process");
            pipeLine.Commands.Add(cmd);
            pipeLine.Invoke();

            if (connect)
            {
                pipeLine = _runSpace.CreatePipeline();
                cmd = new Command("connect-pnponline");
                cmd.Parameters.Add("Url", SiteUrl);
                if (!string.IsNullOrEmpty(CredentialManagerEntry))
                {
                    // Use Windows Credential Manager to authenticate
                    cmd.Parameters.Add("Credentials", CredentialManagerEntry);
                }
                else
                {
                    if (!string.IsNullOrEmpty("AppId") && !string.IsNullOrEmpty("AppSecret"))
                    {
                        // Use oAuth Token to authenticate
                        if (!string.IsNullOrEmpty(Realm))
                        {
                            cmd.Parameters.Add("Realm", Realm);
                        }
                        cmd.Parameters.Add("AppId", AppId);
                        cmd.Parameters.Add("AppSecret", AppSecret);
                    }
                }
                pipeLine.Commands.Add(cmd);
                pipeLine.Invoke();
            }
        }
开发者ID:OfficeDev,项目名称:PnP-PowerShell,代码行数:54,代码来源:PSTestScope.cs

示例3: InitializeTests

        public void InitializeTests()
        {

            RunspaceConfiguration config = RunspaceConfiguration.Create();
            
            PSSnapInException warning;

            config.AddPSSnapIn("ShareFile", out warning);

            runspace = RunspaceFactory.CreateRunspace(config);
            runspace.Open();

            // do login first to start tests
            using (Pipeline pipeline = runspace.CreatePipeline())
            {

                Command command = new Command("Get-SfClient");
                command.Parameters.Add(new CommandParameter("Name", Utils.LoginFilePath));

                pipeline.Commands.Add(command);

                Collection<PSObject> objs = pipeline.Invoke();
                Assert.AreEqual<int>(1, objs.Count);
                sfLogin = objs[0];
            }
        }
开发者ID:wholroyd,项目名称:ShareFile-PowerShell,代码行数:26,代码来源:MapDriveTests.cs

示例4: createRunspace

        private bool createRunspace(string command)
        {
            bool result = false;
            
            // 20131210
            // UIAutomation.Preferences.FromCache = false;
            
            try {
                testRunSpace = null;
                testRunSpace = RunspaceFactory.CreateRunspace();
                testRunSpace.Open();
                Pipeline cmd =
                    testRunSpace.CreatePipeline(command);
                cmd.Invoke();
                result = true;
            }
            catch (Exception eInitRunspace) {

                richResults.Text += eInitRunspace.Message;
                richResults.Text += "\r\n";
                result = false;
            }
            return result;
            //Screen.PrimaryScreen.Bounds.Width
        }
开发者ID:apetrovskiy,项目名称:STUPS,代码行数:25,代码来源:SpyForm.cs

示例5: PipelineExecutor

        public PipelineExecutor(Runspace runSpace, string command)
        {
            this.pipeline = runSpace.CreatePipeline(command);
            this.pipeline.Commands[0].MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output);

            this.pipeline.Output.DataReady += this.OutputDataReady;
            this.pipeline.Error.DataReady += this.ErrorDataReady;
        }
开发者ID:andreaskoch,项目名称:NuDeploy,代码行数:8,代码来源:PipelineExecutor.cs

示例6: run_set_host_command

        void run_set_host_command(Runspace configuredRunspace, string hostName, string address, string hostsFile)
        {
            using (var command = configuredRunspace.CreatePipeline(
                string.Format("set-HostsFileEntry {0} {1} -f \"{2}\"", hostName, address, hostsFile)))
            {
                var results = command.Invoke();

                expect(() => results.Count() == 0);
            }
        }
开发者ID:fschwiet,项目名称:PSHostsFile,代码行数:10,代码来源:SetHostsFileEntryTests.cs

示例7: MakeExternalScriptInfo

 public static ExternalScriptInfo MakeExternalScriptInfo(Runspace powershellRunspace, string exampleScriptName)
 {
     var outputDirectory = new Uri(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase)).LocalPath;
     var exampleScriptPath = Path.Combine(outputDirectory, "ExampleScripts\\" + exampleScriptName + ".ps1");
     var cmd = string.Format("Set-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSigned; Get-Command \"{0}\"", exampleScriptPath);
     using (Pipeline pipeline = powershellRunspace.CreatePipeline(cmd))
     {
         var results = pipeline.Invoke();
         return results.First().BaseObject as ExternalScriptInfo;
     }
 }
开发者ID:tikrimi,项目名称:MvcScaffolding4TwitterBootstrapMvc,代码行数:11,代码来源:ExampleScripts.cs

示例8: InitializeTests

        public void InitializeTests()
        {
            RunspaceConfiguration config = RunspaceConfiguration.Create();

            PSSnapInException warning;

            config.AddPSSnapIn("ShareFile", out warning);

            runspace = RunspaceFactory.CreateRunspace(config);
            runspace.Open();

            // do login first to start tests
            using (Pipeline pipeline = runspace.CreatePipeline())
            {

                Command command = new Command("Get-SfClient");
                command.Parameters.Add(new CommandParameter("Name", Utils.LoginFilePath));

                pipeline.Commands.Add(command);

                Collection<PSObject> psObjects = pipeline.Invoke();
                Assert.AreEqual<int>(1, psObjects.Count);
                sfLogin = psObjects[0];
            }

            using (Pipeline pipeline = runspace.CreatePipeline())
            {
                Command command = new Command("New-PSDrive");
                command.Parameters.Add("Name", Utils.ShareFileDriveLetter);
                command.Parameters.Add("PSProvider", "ShareFile");
                command.Parameters.Add("Root", "/");
                command.Parameters.Add("Client", sfLogin);

                pipeline.Commands.Add(command);

                Collection<PSObject> psObjects = pipeline.Invoke();

                // Drive is successfully mapped to root folder
                Assert.AreEqual<int>(1, psObjects.Count);
            }
        }
开发者ID:wholroyd,项目名称:ShareFile-PowerShell,代码行数:41,代码来源:SyncSFItemsTests.cs

示例9: PowerShellRunner

 public PowerShellRunner()
 {
     var psHost = new PSHost(new PSHostUserInterface(this)); 
     runSpace = RunspaceFactory.CreateRunspace(psHost);
     runSpace.Open();
     // Allows scripts to be run for this process
     using (var pipeline = runSpace.CreatePipeline())
     {
         pipeline.Commands.AddScript("Set-ExecutionPolicy -ExecutionPolicy unrestricted -Scope Process -Force");
         pipeline.Invoke();
     }
 }
开发者ID:nulltoken,项目名称:PlatformInstaller,代码行数:12,代码来源:PowerShellRunner.cs

示例10: Execute

        public static string Execute(bool logErrors, Action<string> onErrorHandler, TestHostUserInterface ui,
                                     params string[] statements)
        {
            if (logErrors)
            {
                ui.OnWriteErrorLineString = onErrorHandler ?? (s => ui.Log.Append(s));
            }

            TestHost host = new TestHost(ui);
            // use public static property, so we can access e.g. the ExecutionContext after execution
            LastUsedRunspace = CreateRunspace(host);
            LastUsedRunspace.Open();
            _doExit = false;
            LastExitCode = null;

            foreach (var statement in statements)
            {
                if (_doExit)
                {
                    break;
                }
                using (var currentPipeline = LastUsedRunspace.CreatePipeline())
                {
                    currentPipeline.Commands.AddScript(statement, false);
                    currentPipeline.Commands.Add("Out-Default");
                    try
                    {
                        currentPipeline.Invoke();
                    }
                    catch (Exception e)
                    {
                        ui.WriteErrorLine(e.ToString());
                    }
                    // pipeline might failed, write errors to ui
                    if (currentPipeline.PipelineStateInfo.State.Equals(PipelineState.Failed))
                    {
                        foreach (var error in currentPipeline.Error.ReadToEnd())
                        {
                            ui.WriteErrorLine(error.ToString());
                        }
                    }
                }
            }

            return ui.Log.ToString();
        }
开发者ID:mauve,项目名称:Pash,代码行数:46,代码来源:TestHost.cs

示例11: RunScript

        private static string RunScript(Runspace runspace)
        {
            runspace.Open();
            var pipeline = runspace.CreatePipeline();

            var runspaceInvoke = new RunspaceInvoke(runspace);
            runspaceInvoke.Invoke("Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process -Force");

            pipeline.Commands.AddScript(@"D:\Projekt\EPiServer\SampleCode\CodeSample\ScheduledJobs\SampleScript.ps1");
            pipeline.Commands.Add("Out-String");

            var stringBuilder = new StringBuilder();
            foreach (var psObject in pipeline.Invoke())
            {
                stringBuilder.AppendLine(psObject.ToString());
            }
            return stringBuilder.ToString();
        }
开发者ID:kirolosgerges,项目名称:Blog,代码行数:18,代码来源:RunPowerShellScript.cs

示例12: PSTestScope

        public PSTestScope(bool connect = true)
        {
            SiteUrl = ConfigurationManager.AppSettings["SPODevSiteUrl"];
            CredentialManagerEntry = ConfigurationManager.AppSettings["SPOCredentialManagerLabel"];
            Realm = ConfigurationManager.AppSettings["Realm"];
            AppId = ConfigurationManager.AppSettings["AppId"];
            AppSecret = ConfigurationManager.AppSettings["AppSecret"];

            var iss = InitialSessionState.CreateDefault();
            if (connect)
            {
                SessionStateCmdletEntry ssce = new SessionStateCmdletEntry("Connect-SPOnline", typeof(ConnectSPOnline), null);

                iss.Commands.Add(ssce);
            }
            _runSpace = RunspaceFactory.CreateRunspace(iss);

            _runSpace.Open();


            if (connect)
            {
                var pipeLine = _runSpace.CreatePipeline();
                Command cmd = new Command("connect-sponline");
                cmd.Parameters.Add("Url", SiteUrl);
                if (!string.IsNullOrEmpty(CredentialManagerEntry))
                {
                    // Use Windows Credential Manager to authenticate
                    cmd.Parameters.Add("Credentials", CredentialManagerEntry);
                }
                else
                {                    
                    if (!string.IsNullOrEmpty(Realm) && !string.IsNullOrEmpty("AppId") && !string.IsNullOrEmpty("AppSecret"))
                    {
                        // Use oAuth Token to authenticate
                        cmd.Parameters.Add("Realm", Realm);
                        cmd.Parameters.Add("AppId", AppId);
                        cmd.Parameters.Add("AppSecret", AppSecret);
                    }
                }
                pipeLine.Commands.Add(cmd);
                pipeLine.Invoke();
            }
        }
开发者ID:sebastienlevert,项目名称:PnP-PowerShell,代码行数:44,代码来源:PSTestScope.cs

示例13: PipelineExecutor

        public PipelineExecutor(Runspace runSpace,ISynchronizeInvoke invoker,string command)
        {
            this.invoker = invoker;

            // initialize delegates
            synchDataReady = new DataReadyDelegate(SynchDataReady);
            synchDataEnd = new DataEndDelegate(SynchDataEnd);
            synchErrorReady = new ErrorReadyDelegate(SynchErrorReady);

            // initialize event members
            stopEvent = new ManualResetEvent(false);
            waitHandles = new WaitHandle[] { null, stopEvent };
            // create a pipeline and feed it the script text
            pipeline = runSpace.CreatePipeline(command);

            // we'll listen for script output data by way of the DataReady event
            pipeline.Output.DataReady += new EventHandler(Output_DataReady);
            pipeline.Error.DataReady += new EventHandler(Error_DataReady);
        }
开发者ID:HydAu,项目名称:PowershellUISamples,代码行数:19,代码来源:PipelineExecutor.cs

示例14: InitializeRunspace

        // ------------------ Methods ----------------------------

        public static bool InitializeRunspace(string command)
        {
            bool result = false;
            try {
                testRunSpace = null;
                testRunSpace = RunspaceFactory.CreateRunspace();
                // testRunSpace.AvailabilityChanged += new EventHandler<RunspaceAvailabilityEventArgs>(runspace_AvailabilityChanged);
                testRunSpace.AvailabilityChanged += runspace_AvailabilityChanged;
                // testRunSpace.StateChanged += new EventHandler<RunspaceStateEventArgs>(runspace_StateChanged);
                testRunSpace.StateChanged += runspace_StateChanged;
                testRunSpace.Open();
                // 20140722
                // pipeline = null;
                
                pipeline = testRunSpace.CreatePipeline(command);
                // pipeline.StateChanged += new EventHandler<PipelineStateEventArgs>(pipeline_StateChanged);
                pipeline.StateChanged += pipeline_StateChanged;
                
//if (PipelineState.Running == pipeline.PipelineStateInfo.State) {
//    pipeline.Stop();
//}
                
                pipeline.Invoke();
                result = true;
            } 
            catch (Exception eInitRunspace) {
                // Console.WriteLine(eInitRunspace.Message);
                //result = false;
                throw (eInitRunspace);
            }
            return result;
        }
开发者ID:apetrovskiy,项目名称:STUPS,代码行数:34,代码来源:Runner.cs

示例15: RunScript

 /// <summary>
 /// Runs a PowerShell script under a given <see cref="Runspace"/>.
 /// </summary>
 /// <param name="runspace">The Runspace to run the script under.</param>
 /// <param name="scriptText">The name of the text file to run as a powershell script.</param>
 /// <param name="outString">Set to true to add an Out-String to the end of the pipeline.</param>
 /// <returns></returns>
 private static Collection<PSObject> RunScript(Runspace runspace, string scriptText, bool outString = false)
 {
     Collection<PSObject> results;
     using (var pipeline = runspace.CreatePipeline())
     {
         pipeline.Commands.AddScript(scriptText);
         if (outString)
         {
             pipeline.Commands[0].MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output);;
             //pipeline.Commands.Add("Out-String");
             pipeline.Commands.Add("Out-Default");
         }
         results = pipeline.Invoke();
     }
     return results;
 }
开发者ID:zippy1981,项目名称:AppDomainPoshRunner,代码行数:23,代码来源:AppDomainPoshRunner.cs


注:本文中的System.Management.Automation.Runspaces.Runspace.CreatePipeline方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。