将 Runspace Factory 用于 Powershell 出现错误 [英] Using Runspace Factory for Powershell Gives Error

查看:44
本文介绍了将 Runspace Factory 用于 Powershell 出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用下面的行时遇到以下错误,直到我在这家新公司开始工作之前我从未见过它.

I'm getting the following error on this using line below, I've never seen it up until I started at this new company.

System.PlatformNotSupportedException:此平台不支持仅反射加载.
在 System.Reflection.Assembly.ReflectionOnlyLoadFrom(String assemblyFile)
在 System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadMshSnapinAssembly(PSSnapInInfo mshsnapinInfo)

System.PlatformNotSupportedException: ReflectionOnly loading is not supported on this platform.
at System.Reflection.Assembly.ReflectionOnlyLoadFrom(String assemblyFile)
at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadMshSnapinAssembly(PSSnapInInfo mshsnapinInfo)

错误发生在 using 语句处.我在 Windows 2008 R2 上使用 Visual Studio 2017.

Error occurs right AT the using statement. I'm using Visual Studio 2017 on Windows 2008 R2.

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 重新创建我的应用程序.

Turns out that powershell runspace factory does not support .NET Core applications. I had to recreate my application using the normal .NET Framework 4.7.1.

这篇关于将 Runspace Factory 用于 Powershell 出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆