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

时间:2014-09-09 08:35:58

标签: .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 -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()
}

1 个答案:

答案 0 :(得分:1)

我发现了问题: 我的Powershell已在powershell.exe.config中配置为.Net 4,但未在wsmprovhost.exe.config中配置。所以我无法从远程会话加载.Net 4程序集。另请参阅this question