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


C# Runspaces.Runspace类代码示例

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


Runspace类属于System.Management.Automation.Runspaces命名空间,在下文中一共展示了Runspace类的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: 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

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

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

示例6: P0wnedListenerConsole

		public P0wnedListenerConsole()
        {
			
			InitialSessionState state = InitialSessionState.CreateDefault();
            state.AuthorizationManager = new System.Management.Automation.AuthorizationManager("Dummy");
			
			this.myHost = new MyHost(this);
            this.myRunSpace = RunspaceFactory.CreateRunspace(this.myHost, state);
            this.myRunSpace.Open();

            lock (this.instanceLock)
            {
                this.currentPowerShell = PowerShell.Create();
            }

            try
            {
                this.currentPowerShell.Runspace = this.myRunSpace;

                PSCommand[] profileCommands = p0wnedShell.HostUtilities.GetProfileCommands("p0wnedShell");
                foreach (PSCommand command in profileCommands)
                {
                    this.currentPowerShell.Commands = command;
                    this.currentPowerShell.Invoke();
                }
            }
            finally
            {
                lock (this.instanceLock)
                {
                    this.currentPowerShell.Dispose();
                    this.currentPowerShell = null;
                }
            }
        }
开发者ID:lei720,项目名称:p0wnedShell,代码行数:35,代码来源:p0wnedListenerConsole.cs

示例7: PipelineBase

        /// <summary>
        /// Create a Pipeline with an existing command string.
        /// Caller should validate all the parameters.
        /// </summary>
        /// <param name="runspace">
        /// The LocalRunspace to associate with this pipeline.
        /// </param>
        /// <param name="command">
        /// The command to invoke.
        /// </param>
        /// <param name="addToHistory"> 
        /// If true, add the command to history.
        /// </param>
        /// <param name="isNested">
        /// If true, mark this pipeline as a nested pipeline.
        /// </param>
        /// <param name="inputStream">
        /// Stream to use for reading input objects.
        /// </param>
        /// <param name="errorStream">
        /// Stream to use for writing error objects.
        /// </param>
        /// <param name="outputStream">
        /// Stream to use for writing output objects.
        /// </param>
        /// <param name="infoBuffers">
        /// Buffers used to write progress, verbose, debug, warning, information
        /// information of an invocation.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Command is null and add to history is true
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// 1. InformationalBuffers is null
        /// </exception>
        protected PipelineBase(Runspace runspace,
            CommandCollection command,
            bool addToHistory,
            bool isNested,
            ObjectStreamBase inputStream,
            ObjectStreamBase outputStream,
            ObjectStreamBase errorStream,
            PSInformationalBuffers infoBuffers)
            : base(runspace, command)
        {
            Dbg.Assert(null != inputStream, "Caller Should validate inputstream parameter");
            Dbg.Assert(null != outputStream, "Caller Should validate outputStream parameter");
            Dbg.Assert(null != errorStream, "Caller Should validate errorStream parameter");
            Dbg.Assert(null != infoBuffers, "Caller Should validate informationalBuffers parameter");
            Dbg.Assert(null != command, "Command cannot be null");

            // Since we are constructing this pipeline using a commandcollection we dont need
            // to add cmd to CommandCollection again (Initialize does this).. because of this
            // I am handling history here..
            Initialize(runspace, null, false, isNested);
            if (true == addToHistory)
            {
                // get command text for history..
                string cmdText = command.GetCommandStringForHistory();
                HistoryString = cmdText;
                AddToHistory = addToHistory;
            }

            //Initialize streams
            InputStream = inputStream;
            OutputStream = outputStream;
            ErrorStream = errorStream;
            InformationalBuffers = infoBuffers;
        }
开发者ID:40a,项目名称:PowerShell,代码行数:69,代码来源:pipelinebase.cs

示例8: GetCommandSynopsis

        /// <summary>
        /// Gets the command's "Synopsis" documentation section.
        /// </summary>
        /// <param name="commandInfo">The CommandInfo instance for the command.</param>
        /// <param name="runspace">The Runspace to use for getting command documentation.</param>
        /// <returns></returns>
        public static string GetCommandSynopsis(
            CommandInfo commandInfo, 
            Runspace runspace)
        {
            string synopsisString = string.Empty;

            PSObject helpObject = null;

            using (PowerShell powerShell = PowerShell.Create())
            {
                powerShell.Runspace = runspace;
                powerShell.AddCommand("Get-Help");
                powerShell.AddArgument(commandInfo);
                helpObject = powerShell.Invoke<PSObject>().FirstOrDefault();
            }

            if (helpObject != null)
            {
                // Extract the synopsis string from the object
                synopsisString =
                    (string)helpObject.Properties["synopsis"].Value ??
                    string.Empty;

                // Ignore the placeholder value for this field
                if (string.Equals(synopsisString, "SHORT DESCRIPTION", System.StringComparison.InvariantCultureIgnoreCase))
                {
                    synopsisString = string.Empty;
                }
            }

            return synopsisString;
        }
开发者ID:juvchan,项目名称:PowerShellEditorServices,代码行数:38,代码来源:CommandHelpers.cs

示例9: SymbolDetails

        internal SymbolDetails(
            SymbolReference symbolReference, 
            Runspace runspace)
        {
            this.SymbolReference = symbolReference;

            // If the symbol is a command, get its documentation
            if (symbolReference.SymbolType == SymbolType.Function)
            {
                CommandInfo commandInfo =
                    CommandHelpers.GetCommandInfo(
                        symbolReference.SymbolName,
                        runspace);

                this.Documentation =
                    CommandHelpers.GetCommandSynopsis(
                        commandInfo,
                        runspace);

                this.DisplayString = "function " + symbolReference.SymbolName;
            }
            else if (symbolReference.SymbolType == SymbolType.Parameter)
            {
                // TODO: Get parameter help
                this.DisplayString = "(parameter) " + symbolReference.SymbolName;
            }
            else if (symbolReference.SymbolType == SymbolType.Variable)
            {
                this.DisplayString = symbolReference.SymbolName;
            }
        }
开发者ID:juvchan,项目名称:PowerShellEditorServices,代码行数:31,代码来源:SymbolDetails.cs

示例10: EmbeddableRunspace

 public EmbeddableRunspace(NotifyPSHostExit notifyPSHostExit)
 {
     this.embeddedPSHost = new EmbeddablePSHost(notifyPSHostExit);
     this.runspace = RunspaceFactory.CreateRunspace(embeddedPSHost);
     this.runspace.Open();
     RunScript("Add-PsSnapin LabLauncherTunnel");
 }
开发者ID:broliver,项目名称:LabLauncher,代码行数:7,代码来源:EmbeddableRunspace.cs

示例11: RemotePipeline

        /// <summary>
        /// Private constructor that does most of the work constructing a remote pipeline object.
        /// </summary>
        /// <param name="runspace">RemoteRunspace object</param>
        /// <param name="addToHistory">AddToHistory</param>
        /// <param name="isNested">IsNested</param>
        private RemotePipeline(RemoteRunspace runspace, bool addToHistory, bool isNested)
            : base(runspace)
        {
            _addToHistory = addToHistory;
            _isNested = isNested;
            _isSteppable = false;
            _runspace = runspace;
            _computerName = ((RemoteRunspace)_runspace).ConnectionInfo.ComputerName;
            _runspaceId = _runspace.InstanceId;

            //Initialize streams
            _inputCollection = new PSDataCollection<object>();
            _inputCollection.ReleaseOnEnumeration = true;

            _inputStream = new PSDataCollectionStream<object>(Guid.Empty, _inputCollection);
            _outputCollection = new PSDataCollection<PSObject>();
            _outputStream = new PSDataCollectionStream<PSObject>(Guid.Empty, _outputCollection);
            _errorCollection = new PSDataCollection<ErrorRecord>();
            _errorStream = new PSDataCollectionStream<ErrorRecord>(Guid.Empty, _errorCollection);

            // Create object stream for method executor objects.
            MethodExecutorStream = new ObjectStream();
            IsMethodExecutorStreamEnabled = false;

            SetCommandCollection(_commands);

            //Create event which will be signalled when pipeline execution
            //is completed/failed/stoped. 
            //Note:Runspace.Close waits for all the running pipeline
            //to finish.  This Event must be created before pipeline is 
            //added to list of running pipelines. This avoids the race condition
            //where Close is called after pipeline is added to list of 
            //running pipeline but before event is created.
            PipelineFinishedEvent = new ManualResetEvent(false);
        }
开发者ID:40a,项目名称:PowerShell,代码行数:41,代码来源:remotepipeline.cs

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

示例13: Dispose

 /// <summary>
 /// Disposes the RunspaceHandle once the holder is done using it.
 /// Causes the handle to be released back to the PowerShellContext.
 /// </summary>
 public void Dispose()
 {
     // Release the handle and clear the runspace so that
     // no further operations can be performed on it.
     this.powerShellContext.ReleaseRunspaceHandle(this);
     this.Runspace = null;
 }
开发者ID:modulexcite,项目名称:PowerShellEditorServices,代码行数:11,代码来源:RunspaceHandle.cs

示例14: WishModel

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

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


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