【发布时间】:2021-10-29 04:35:40
【问题描述】:
我正在使用 InitialSessionState 类来准备 Powershell 运行空间并预加载一些模块。
iss = InitialSessionState.CreateDefault();
iss.ImportPSModule(new[] { "SomeModules" });
//iss.ImportPSSnapIn("Microsoft.Exchange.Management.PowerShell.SnapIn", out psEx);
iss.ThrowOnRunspaceOpenError = true;
rs = RunspaceFactory.CreateRunspace(iss);
rs.Open();
很遗憾,无法预加载 Powershell 管理单元(如 Exchange 命令行管理程序),因为该方法已被标记为已弃用:https://docs.microsoft.com/en-us/dotnet/api/system.management.automation.runspaces.initialsessionstate.importpssnapin?view=powershellsdk-7.0.0
这种方法有什么替代方法吗?无法将 Snapin 作为模块加载。
【问题讨论】:
标签: c# visual-studio powershell