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

Method invocation failed while trying to create a pop up

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

$out.popup("Network status",0,"Done",0x1)

Error : Method invocation failed because [Selected.System.Management.ManagementObject] does not contain a method named 'popup'. At line:2 char:1 + $out.popup("Network status",0,"Done",0x1) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     + CategoryInfo          : InvalidOperation: (popup:String) [], RuntimeException     + FullyQualifiedErrorId : MethodNotFound

using assembly System.Windows.Forms
using namespace System.Windows.Forms
[messagebox]::show('hello world')

PopUp 是从 Wscript.Shell class 调用的方法。它不适用于 WMI 实例对象(或实例集合)。如果您想使用示例中的 pop-up 样式消息框显示该 WMI 查询的结果,您将必须执行类似的操作。

$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)

或者您可以通过将数据通过管道传输到 gridview 来稍微简化它。

Get-WmiObject -class Win32_PerfFormattedData_Tcpip_NetworkInterface | select name , BytesTotalPersec | Out-GridView

希望对您有所帮助。