繁体   English   中英

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

[英]Why Runspace in Powershell scripts in C#

我想澄清一件事,为什么我们在C#运行PowerShell脚本时使用Runspace 即使没有Runspace它也可以运行。

如果可以在不运行的Runspace ,为什么我们需要什么?

例如:

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

即使没有Runspace这也将起作用。 那为什么呢?

运行空间提供用于创建管道,访问会话状态等的API。

使用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