.net 无法在powershell远程会话中加载文件或程序集

.net 无法在powershell远程会话中加载文件或程序集,.net,powershell,powershell-remoting,.net,Powershell,Powershell Remoting,尝试从powershell远程会话运行程序集时出现此错误 Could not load file or assembly 'System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified. 我已通过启动远程会话 Enter-PsSession -Comp

尝试从powershell远程会话运行程序集时出现此错误

Could not load file or assembly 'System.Xml.Linq, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find
the file specified.
我已通过启动远程会话

Enter-PsSession -ComputerName myComputer -ConfigurationName Microsoft.Powershell
-Credential domain\user
但是当我在同一台机器上和同一个用户运行它时,它没有问题

更新:

我想做一些像

if (Test-Path $AssemblyPath) {
    $fileStream = ([System.IO.FileInfo] (Get-Item $AssemblyPath)).OpenRead()
    $assemblyBytes = New-Object byte[] $fileStream.Length
    $fileStream.Read($assemblyBytes, 0, $fileStream.Length) | Out-Null
    $fileStream.Close()
    $assemblyLoaded = [System.Reflection.Assembly]::Load($assemblyBytes) | Out-Null

    $myObject = New-Object namespaceInMyAssembly.ClassInMyAssembly
    $myObject.doMyAction()
}
我发现了问题:
我的Powershell已在Powershell.exe.config中为.Net 4配置,但未在wsmprovhost.exe.config中配置。因此,我无法从远程会话加载.Net 4程序集。另请参见。

我不确定“运行程序集”是什么意思。你能发布一些示例脚本来演示这个问题吗?远程计算机是否安装了.NET 4.0、4.5、4.5.1或4.5.2?@JamesQMurphy:我只是调用了一个.exe,但当我手动加载.exe并创建一个对象并执行一个方法(通过新对象)时,我也会遇到同样的问题@KeithHill:计算机已安装“.NET 4多目标包”和“.NET Framework 4.5.1”。远程处理终结点
Microsoft.PowerShell
为64位。您试图加载的程序集是否为x86体系结构(32位)?顺便问一下,为什么不直接使用
添加类型-Path$AssemblyPath
?您使用的是什么版本的PowerShell-v2?