我正在更新一个使用System.Management.Automation.dll
v10.0.10586的旧应用程序,NuGet
例如PowerShell 3.0
我的新应用是.NET 5
并且我已经从 NuGet 添加了 System.Management.Automation 和 Microsoft.PowerShell.SDK 的 v7.1.0
但是运行基本代码来测试在旧版本上运行良好的代码不适用于新版本,我很困惑
例如,下面的代码片段给出了一个错误
Dim ps As PowerShell = PowerShell.Create()
ps.AddCommand("test-netconnection")
Dim result = ps.Invoke()
MsgBox(result(0).Properties("PingSucceeded").Value.ToString)
ps.Dispose()
错误:
“System.Management.Automation.CommandNotFoundException:在模块‘NetTCPIP’中找到‘test-netconnection’命令,但无法加载模块。”
请有人可以告诉为什么以前有效的方法现在不起作用?
我已经从标准PowerShell 7
控制台尝试过并且test-netconnection
工作正常