【问题标题】:Running Powershell 5.1 in a C# / .NET Core 2.1 Application在 C#/.NET Core 2.1 应用程序中运行 Powershell 5.1
【发布时间】:2019-11-08 18:44:46
【问题描述】:

我正在尝试将应用程序从 .NET 4.5 迁移到 .NET Core 2.1。

此应用程序正在使用 System.Management.Automation dll 来执行 powershell 命令和脚本。 我需要使用 SDK 中的一些 PSSnapin,但我不知道是否可以在 .NET Core 2.1 中获得这些功能

我尝试使用 InitialSessionState 导入我的管理单元,但它返回类型为 PSSnapin 的 TypeLoadException。 https://docs.microsoft.com/en-us/dotnet/api/system.management.automation.runspaces.initialsessionstate.importpssnapin?view=pscore-6.2.0#System_Management_Automation_Runspaces_InitialSessionState_ImportPSSnapIn_System_String_System_Management_Automation_Runspaces_PSSnapInException__

那么我可以在 C# 中使用 PowershellCore 加载我的 PSSnapin 吗?或者我可以从 .NET Core 2.1 访问 System.Management.Automation 以继续调用脚本吗?

【问题讨论】:

    标签: c# powershell .net-core powershell-core pssnapin


    【解决方案1】:

    我终于放弃了在 net core 中加载我的 snapins。
    我现在在具有 powershell 5.1 和我想要使用的管理单元的服务器上使用远程运行空间。

    【讨论】:

      猜你喜欢
      • 2018-11-27
      • 1970-01-01
      • 2020-04-27
      • 2021-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多