Powershell 2.0 远程加载 .Net 4.0 dll

标签 powershell .net-4.0 powershell-remoting

我正在尝试在远程 Powershell 2.0 session 中使用 [Reflection.Assembly]::LoadFrom 加载 .Net 4.0 程序集。由于我对 powershell.exe.config 文件进行了更改,它在本地工作,但在远程 session 中失败并显示“此程序集由运行时更新...”异常。

所涉及的两台机器都具有 .Net 2.0 和 4.0,并且对 x86 和 x64 位 powershell 可执行文件进行了 powershell.exe.config 更改。我还尝试更改服务器 powershell 注册表项:
HKLM:\Software\Microsoft\Powershell\1\PowerShellEngine\RuntimeVersion
HKLM:\Software\Wow6432Node\Microsoft\Powershell\1\PowerShellEngine\RuntimeVersion

我一定错过了一些东西,但我不知道它是什么。

编辑:
以下是我正在执行的代码示例。

PS C:\>Enter-PSSession -ComputerName server1
[server1]: PS C:\stuff> dir *.dll | foreach { [Reflection.Assembly]::LoadFrom( $_.FullName ) }

最佳答案

解决方法是创建一个 c:\windows\System32\wsmprovhost.exe.config 文件和一个 c:\windows\SysWOW64\wsmprovhost.exe.config 文件,在服务器上 ,类似于我在以下位置找到的:http://poshcode.com/2045

<?xml version="1.0" ?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" />
    <supportedRuntime version="v2.0" />
  </startup>
</configuration>

我发现了以下文章,其中暗示 wsmprovhost.exe 需要像 powershell.exe 文件一样进行配置。
http://tfl09.blogspot.com/2010/08/using-later-versions-of-net-framework.html

关于Powershell 2.0 远程加载 .Net 4.0 dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4631710/

相关文章:

c# - 随着时间的流逝,Parallel ForEach 只消耗很少的处理能力

powershell - 使用 PowerShell 以管理员身份运行命令?

powershell - 使用PowerShell ADSI提供程序将组添加到组

.net - OrderedDictionary 在 .NET 4 中发生了重大变化?

c# - C# 中的 Task<T> 和 TaskContinuationOptions 说明?

powershell - Exchange Remote Powershell 出现零星 'Broken' 状态

c# - 为什么 PowerShell 类不加载管理单元

powershell - 如何在企业中使用 PowerShell 和 PowerShell 模块

azure - WSL2 上的 powershell 浏览器访问

powershell - 在Powershell中显示Unicode