![](/img/trans.png)
[英]PowerShell Runspace to Exchange Online Budget Exceeded Error
[英]Using Runspace Factory for Powershell Gives Error
我在使用下面的行时收到以下错误,直到我在这家新公司开始工作之前我从未见过它。
System.PlatformNotSupportedException:此平台不支持 ReflectionOnly 加载。
在 System.Reflection.Assembly.ReflectionOnlyLoadFrom(String assemblyFile)
在 System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadMshSnapinAssembly(PSSnapInInfo mshsnapinInfo)
错误发生在 using 语句中。 我在 Windows 2008 R2 上使用 Visual Studio 2017。
using (Runspace runspace = RunspaceFactory.CreateRunspace())
{
runspace.Open();
PowerShell ps = PowerShell.Create();
ps.Runspace = runspace;
PSSnapInException psex;
runspace.RunspaceConfiguration.AddPSSnapIn("Citrix*", out psex);
Pipeline pipeline = runspace.CreatePipeline();
Command getSession = new Command("Get-XASession");
getSession.Parameters.Add("-ComputerName", serverName);
getSession.Parameters.Add("-AccountDisplayName", objWINS + "\\" + strUser);
pipeline.Commands.Add(getSession);
Collection<PSObject> output = pipeline.Invoke();
}
事实证明,powershell 运行空间工厂不支持 .NET Core 应用程序。 我不得不使用普通的 .NET Framework 4.7.1 重新创建我的应用程序。
我不知道这个包是否比您的问题更新,但 2020 年的正确答案是坚持使用 dotnet 核心并使用正确的包。
dotnet add package Microsoft.PowerShell.SDK
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.