0

我正在尝试将应用程序从 .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 以继续调用脚本吗?

4

1 回答 1

0

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

于 2019-11-15T14:01:28.040 回答