使用设置对象时,如何禁止/隐藏WMI输出?

时间:2016-02-26 15:03:25

标签: powershell wmi

如何在powershell函数中抑制WMI Set的输出?

Function ChangeDefaultGateway ($NewDefaultGateway, $ComputerName)
{
    $MyIPSubnet = "192.168.16."  # This is needed to find which NIC has an assigned Default Gateway
    $NICs = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName "$ComputerName" -Filter “IPEnabled=TRUE”
    foreach($NIC in $NICs) 
    {
        if($NIC.DefaultIPGateway -match $MyIPSubnet) # fetch the NIC that has a gateway address already
        {
            write-host "Changing Gateway for $ComputerName on" $NIC.IPAddress $NIC.Description "from" $NIC.DefaultIPGateway "to" $NewDefaultGateway
            $NIC.SetGateways($NewDefaultGateway)
        }
    }
}

这是输出:

Changing Gateway for DT-jesse on 192.168.16.108 Intel(R) 82579LM Gigabit Network Connection from 192.168.16.2 to 192.168.16.2


__GENUS          : 2
__CLASS          : __PARAMETERS
__SUPERCLASS     : 
__DYNASTY        : __PARAMETERS
__RELPATH        : 
__PROPERTY_COUNT : 1
__DERIVATION     : {}
__SERVER         : 
__NAMESPACE      : 
__PATH           : 
ReturnValue      : 0
PSComputerName   : 

有没有办法抑制/隐藏$ NIC.SetGateways($ NewDefaultGateway)生成的输出?

0 个答案:

没有答案