简体   繁体   English

为什么在C#中的Powershell脚本中运行空间

[英]Why Runspace in Powershell scripts in C#

I want to be clear about one thing that why we are using Runspace while running the PowerShell scripts in C# . 我想澄清一件事,为什么我们在C#运行PowerShell脚本时使用Runspace It runs even though the absence of Runspace . 即使没有Runspace它也可以运行。

If it can be run without the Runspace why we need? 如果可以在不运行的Runspace ,为什么我们需要什么?

For eg: 例如:

PowerShell ps = PowerShell.Create();
ps.AddScript("Import-Module AzureAD");

This will work even though the absence of Runspace . 即使没有Runspace这也将起作用。 So Why is it? 那为什么呢?

Runspace provides APIs for creating pipelines, access session state etc. 运行空间提供用于创建管道,访问会话状态等的API。

When using PowerShell , we need to use System.Management.Automation.PowerShell , it is using System.Management.Automation.Runspaces . 使用PowerShell ,我们需要使用System.Management.Automation.PowerShell ,它使用的是System.Management.Automation.Runspaces

using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Management.Automation.Runspaces;

namespace System.Management.Automation
{
    public sealed class PowerShell : IDisposable
    {
        ......
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM