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

C# 为什么要在C中的Powershell脚本中使用运行空间#,c#,powershell,azure,runspace,C#,Powershell,Azure,Runspace,我想明确一点,为什么在C中运行PowerShell脚本时使用Runspace。即使缺少运行空间,它也会运行 如果它可以在没有运行空间的情况下运行为什么需要 例如: PowerShell ps = PowerShell.Create(); ps.AddScript("Import-Module AzureAD"); 即使缺少运行空间,这也会起作用。那么为什么呢?运行空间提供了用于创建管道、访问会话状态等的API 当使用PowerShell时,我们需要使用System.Management.Aut

我想明确一点,为什么在
C
中运行PowerShell脚本时使用
Runspace
。即使缺少
运行空间
,它也会运行

如果它可以在没有
运行空间的情况下运行
为什么需要

例如:

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

即使缺少
运行空间
,这也会起作用。那么为什么呢?

运行空间提供了用于创建管道、访问会话状态等的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
    {
        ......
    }
}

默认情况下,将创建哪个运行空间会话?@SaravananKS我不确定,但允许您定义在创建会话状态时应显示的元素集。