Powershell 尝试创建弹出窗口时方法调用失败

Powershell 尝试创建弹出窗口时方法调用失败,powershell,powershell-2.0,powershell-3.0,azure-powershell,powershell-core,Powershell,Powershell 2.0,Powershell 3.0,Azure Powershell,Powershell Core,错误:方法调用失败,因为 [Selected.System.Management.ManagementObject]不包含 名为“popup”的方法。第2行字符:1 +$out.popup(“网络状态”,0,“完成”,0x1) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +CategoryInfo:InvalidOperation:(弹出:字符串)[],运行时异常 +FullyQualifiedErrorId:MethodNotFound PopUp是

错误:方法调用失败,因为 [Selected.System.Management.ManagementObject]不包含 名为“popup”的方法。第2行字符:1 +$out.popup(“网络状态”,0,“完成”,0x1) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +CategoryInfo:InvalidOperation:(弹出:字符串)[],运行时异常 +FullyQualifiedErrorId:MethodNotFound


PopUp是从Wscript.Shell类调用的方法。它无法从WMI实例对象(或实例集合)工作。如果希望使用示例中的弹出式消息框显示WMI查询的结果,则必须执行以下操作

using assembly System.Windows.Forms
using namespace System.Windows.Forms
[messagebox]::show('hello world')
或者,您可以通过将数据管道化到gridview来简化它

$out = Get-WmiObject -class Win32_PerfFormattedData_Tcpip_NetworkInterface | select name , BytesTotalPersec | Out-String

$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("Network Status:`n $out",0,"Done",0x1)

希望这能有所帮助。

正如错误所说,该对象没有弹出方法。请允许我向新来者提供标准建议:如果答案解决了您的问题,请单击大复选标记接受它(✓) 在它旁边,也可以选择向上投票(向上投票要求至少15个信誉点)。如果您发现其他答案有帮助,请向上投票。接受(您将获得2个信誉点)和向上投票有助于未来的读者。有关更多信息,请参阅。如果您的问题尚未完全回答,请提供反馈或建议。
$out = Get-WmiObject -class Win32_PerfFormattedData_Tcpip_NetworkInterface | select name , BytesTotalPersec | Out-String

$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("Network Status:`n $out",0,"Done",0x1)
Get-WmiObject -class Win32_PerfFormattedData_Tcpip_NetworkInterface | select name , BytesTotalPersec | Out-GridView