提问人:Roman 提问时间:7/1/2023 更新时间:7/1/2023 访问量:41
如何处理系统。Powershell 6+ 中不再存在的程序集?
How to handle System. assemblies that no longer exist in Powershell 6+?
问:
我有一个由 Joel Bennett 编写的模块(模拟),它允许我更改活动凭据,以便我可以访问远程计算机上的文件共享。它在 Windows PowerShell 5.1 中工作。但是,它在 Powershell 7.3.4(或显然任何 6+)中不起作用。它给出错误
找不到类型 [System.Collections.Generic.Stack[System.Security.Principal.WindowsImpersonationContext]]:验证是否加载了包含此类型的程序集。
因此,就 Powershell 而言,这些系统程序集/类型都不存在。两年前,Jordan Borean 说过,人们可以用类似的东西来调用 5.1 版会话
$s = New-PSSession -UseWindowsPowerShell
Invoke-Command $s { My-LegacyCmdlet ... }
Remove-PSSession $s
此外,“Add-Type 的行为及其隐式加载的引用程序集在 PowerShell 5 和 6+ 之间发生了变化。它与代码一起加载的内容要保守得多,System.Security.Principal 通常是其中之一。这是实际的一个例子,需要做些什么来修复它 https://gist.github.com/jborean93/a7c181b1ea0a4c0c8b815af9a8cbe508#file-start-processex-ps1-L8-L1735。我点击了那个链接,但我认为这超出了我的范围,没有任何解释。那么,我应该尝试将所有旧脚本包装在 New-PsSession 中,还是现在有更好的方法来修复模块或使程序集可用或其他东西?
答: 暂无答案
评论
Invoke-WithImpersonation
:)?据我所知,它与 7+ 兼容-UseWindowsPowerShell
Import-Module
Add-Type
Add-Type