我想在特殊的弹出窗口中输出此powershell脚本吗?

时间:2019-12-24 15:18:38

标签: powershell powershell-2.0 powershell-3.0

下面的代码在powershell中,该代码已成功执行,但我希望在特殊的“弹出窗口”中输出该结果

$ComputerName = $s = $(Get-WmiObject Win32_Computersystem).name
foreach ($Computer in $ComputerName) {
    if(Test-Connection -ComputerName $Computer -Count 1 -ea 0) {
        $Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Computer | ? {$_.IPEnabled}
        foreach ($Network in $Networks) {
            $IPAddress  = $Network.IpAddress[0]
            $SubnetMask  = $Network.IPSubnet[0]
            $DefaultGateway = $Network.DefaultIPGateway
            $DNSServers  = $Network.DNSServerSearchOrder
            $OutputObj  = New-Object -Type PSObject
            $OutputObj | Add-Member -MemberType NoteProperty -Name IPAddress -Value $IPAddress
            $OutputObj | Add-Member -MemberType NoteProperty -Name SubnetMask -Value $SubnetMask
            $OutputObj | Add-Member -MemberType NoteProperty -Name Gateway -Value $DefaultGateway
            $OutputObj | Add-Member -MemberType NoteProperty -Name DNSServers -Value $DNSServers
        }
    }
}

1 个答案:

答案 0 :(得分:0)

powershell中最熟悉的数据显示器是使用 Out-gridview 方法:

如果您想轻松一点,可以这样做:

$ComputerName = $s = $(Get-WmiObject Win32_Computersystem).name
$Pop_Window = foreach ($Computer in $ComputerName) {
    if(Test-Connection -ComputerName $Computer -Count 1 -ea 0) {
        $Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Computer | ? {$_.IPEnabled}
        foreach ($Network in $Networks) {
            $IPAddress  = $Network.IpAddress[0]
            $SubnetMask  = $Network.IPSubnet[0]
            $DefaultGateway = $Network.DefaultIPGateway
            $DNSServers  = $Network.DNSServerSearchOrder
            $OutputObj | Add-Member -MemberType NoteProperty -Name IPAddress -Value $IPAddress
            $OutputObj | Add-Member -MemberType NoteProperty -Name SubnetMask -Value $SubnetMask
            $OutputObj | Add-Member -MemberType NoteProperty -Name Gateway -Value $DefaultGateway
            $OutputObj | Add-Member -MemberType NoteProperty -Name DNSServers -Value $DNSServers

            #output the object:
            $OutputObj
        }
    }
}

$Pop_Window | Out-GridView

如果您要按自己的方式进行设计,那么在Powershell中这将是一件困难而又麻烦的任务,因为您始终必须调用 System.Windows.Forms 类及其子类标签,按钮,文本等类。