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


C# Runspace.Open方法代码示例

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


在下文中一共展示了Runspace.Open方法的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: WishModel

 public WishModel()
 {
     _runspace = RunspaceFactory.CreateRunspace();
     _runspace.Open();
     _runner = new Powershell(_runspace);
     _repl = new Repl(_runner);
 }
开发者ID:neiz,项目名称:Wish,代码行数:7,代码来源:WishModel.cs

示例3: HookInjection

        public HookInjection(
            RemoteHooking.IContext InContext,
            String InChannelName,
            String entryPoint,
            String dll,
            String returnType,
            String scriptBlock,
            String modulePath,
            String additionalCode,
            bool eventLog)
        {
            Log("Opening hook interface channel...", eventLog);
            Interface = RemoteHooking.IpcConnectClient<HookInterface>(InChannelName);
            try
            {
                Runspace = RunspaceFactory.CreateRunspace();
                Runspace.Open();

                //Runspace.SessionStateProxy.SetVariable("HookInterface", Interface);
            }
            catch (Exception ex)
            {
                Log("Failed to open PowerShell runspace." + ex.Message, eventLog);
                Interface.ReportError(RemoteHooking.GetCurrentProcessId(), ex);
            }
        }
开发者ID:adamdriscoll,项目名称:PoshInternals,代码行数:26,代码来源:HookInject.cs

示例4: ScriptDebugger

        public ScriptDebugger(bool overrideExecutionPolicy, DTE2 dte2)
        {
            HostUi = new HostUi(this);

            InitialSessionState iss = InitialSessionState.CreateDefault();
            iss.ApartmentState = ApartmentState.STA;
            iss.ThreadOptions = PSThreadOptions.ReuseThread;


            _runspace = RunspaceFactory.CreateRunspace(this, iss);
            _runspace.Open();

            _runspaceRef = new RunspaceRef(_runspace);
            //TODO: I think this is a v4 thing. Probably need to look into it.
            //_runspaceRef.Runspace.Debugger.SetDebugMode(DebugModes.LocalScript | DebugModes.RemoteScript);
            
            //Provide access to the DTE via PowerShell. 
            //This also allows PoshTools to support StudioShell.
            _runspace.SessionStateProxy.PSVariable.Set("dte", dte2);
            ImportPoshToolsModule();
            LoadProfile();

            if (overrideExecutionPolicy)
            {
                SetupExecutionPolicy();
            }

            SetRunspace(Runspace);
        }
开发者ID:vairam-svs,项目名称:poshtools,代码行数:29,代码来源:VSXHost.cs

示例5: RawExecute

 public static Collection<PSObject> RawExecute(string[] commands)
 {
     LastRawResults = null;
     LastUsedRunspace = InitialSessionState == null ?
         RunspaceFactory.CreateRunspace() : RunspaceFactory.CreateRunspace(InitialSessionState);
     LastUsedRunspace.Open();
     foreach (var command in commands)
     {
         using (var pipeline = LastUsedRunspace.CreatePipeline())
         {
             pipeline.Commands.AddScript(command, true);
             try
             {
                 LastRawResults = pipeline.Invoke();
             }
             catch (Exception)
             {
                 LastRawResults = pipeline.Output.ReadToEnd();
                 throw;
             }
             if (pipeline.Error.Count > 0)
             {
                 throw new MethodInvocationException(String.Join(Environment.NewLine, pipeline.Error.ReadToEnd()));
             }
         }
     }
     return LastRawResults;
 }
开发者ID:prateek,项目名称:Pash,代码行数:28,代码来源:ReferenceHost.cs

示例6: 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

示例7: 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

示例8: ExchPowershell

        /// <summary>
        /// Creates a new class and stores the passed values containing connection information
        /// </summary>
        /// <param name="uri">The URI to the Exchange powershell virtual directory</param>
        /// <param name="username">DOMAIN\Username to authenticate with</param>
        /// <param name="password">Password for the domain user</param>
        /// <param name="isKerberos">True if using kerberos authentication, False if using basic authentication</param>
        /// <param name="domainController">The domain controller to communicate with</param>
        public ExchPowershell()
        {
            try
            {
                // Retrieve the settings from the database
                SchedulerRetrieve.GetSettings();

                // Set our domain controller to communicate with
                this.domainController = Config.PrimaryDC;

                // Get the type of Exchange connection
                bool isKerberos = false;
                if (Config.ExchangeConnectionType == Enumerations.ConnectionType.Kerberos)
                    isKerberos = true;

                // Create our connection
                this.wsConn = GetConnection(Config.ExchangeURI, Config.Username, Config.Password, isKerberos);

                // Create our runspace
                runspace = RunspaceFactory.CreateRunspace(wsConn);

                // Open our connection
                runspace.Open();
            }
            catch (Exception ex)
            {
                // ERROR
                logger.Fatal("Unable to establish connection to Exchange.", ex);
            }
        }
开发者ID:KnowMoreIT,项目名称:CloudPanel_3.0,代码行数:38,代码来源:ExchPowershell.cs

示例9: AppFabricPowershellCommandRunner

 public AppFabricPowershellCommandRunner()
 {
     _state = InitialSessionState.CreateDefault();
     _state.ImportPSModule(new string[] { "DistributedCacheAdministration", "DistributedCacheConfiguration" });
     _state.ThrowOnRunspaceOpenError = true;
     _runspace = RunspaceFactory.CreateRunspace(_state);
     _runspace.Open();
 }
开发者ID:gartdan,项目名称:AppFabricPowershellSample,代码行数:8,代码来源:AppFabricPowershellCommandRunner.cs

示例10: PipelineFixture

        public PipelineFixture()
        {
            var runspaceConfiguration = RunspaceConfiguration.Create();
            runspaceConfiguration.Providers.Append(new ProviderConfigurationEntry(CloudProvider.PROVIDER_NAME, typeof(CloudProvider), null));

            runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration);
            runspace.Open();
        }
开发者ID:viciousviper,项目名称:PowerShellCloudProvider,代码行数:8,代码来源:PipelineFixture.cs

示例11: ImportModule

 private void ImportModule()
 {
     InitialSessionState initial = InitialSessionState.CreateDefault();
     string assemblyPath = Path.Combine(Environment.CurrentDirectory, @"..\..\..\..\src\PackageManagement.PowerShellCmdlets\bin\debug\NuGet.PackageManagement.PowerShellCmdlets.dll");
     initial.ImportPSModule(new string[] { assemblyPath });
     _runSpace = RunspaceFactory.CreateRunspace(initial);
     _runSpace.Open();
 }
开发者ID:pabomex,项目名称:NuGet.PackageManagement,代码行数:8,代码来源:program.cs

示例12: PSListenerConsoleSample

 /// <summary>
 /// Create this instance of the console listener.
 /// </summary>
 PSListenerConsoleSample()
 {
     // Create the host and runspace instances for this interpreter. Note that
     // this application doesn't support console files so only the default snapins
     // will be available.
     myHost = new MyHost(this);
     myRunSpace = RunspaceFactory.CreateRunspace(myHost);
     myRunSpace.Open();
 }
开发者ID:dbremner,项目名称:Windows-classic-samples,代码行数:12,代码来源:Host03.cs

示例13: CompletionProvider

        public CompletionProvider(IBackendContext backendContext, LanguageContext languageContext)
        {
            _languageContext = languageContext;
            _backendContext = backendContext;
            _snippetsCollection = AppContext.Resolve<ISnippetsCollection>();

            _runspace = RunspaceFactory.CreateRunspace();
            _runspace.Open();
        }
开发者ID:peterschen,项目名称:SMAStudio,代码行数:9,代码来源:CompletionProvider.cs

示例14: AsyncPowershellRunnerForm

 public AsyncPowershellRunnerForm()
 {
     InitializeComponent();
     InitializeComboBox();
     // create Powershell runspace
     runSpace = RunspaceFactory.CreateRunspace();
     // open it
     runSpace.Open();
 }
开发者ID:HydAu,项目名称:PowershellUISamples,代码行数:9,代码来源:AsyncPowershellRunnerForm.cs

示例15: PowerShellScriptingContext

 /// <summary>
 /// Initializes a new instance of the <see cref="PowerShellScriptingContext"/> class.
 /// </summary>
 public PowerShellScriptingContext()
     : base("PS> ")
 {
     _host = new PowerShellHost(Output);
     _runspace = RunspaceFactory.CreateRunspace(_host);
     Runspace.DefaultRunspace = _runspace;
     _runspace.Open();
     UpdatePrompt();
 }
开发者ID:schuster-rainer,项目名称:scripting-shell,代码行数:12,代码来源:PowerShellScriptingContext.cs


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