筛选名称:Get-WmiObject Win32_NetworkAdapter

Filtering Names: Get-WmiObject Win32_NetworkAdapter

作为我的清单脚本的一部分,我想添加是否启用 DHCP 的查询 我需要采样以以下开头的网卡:“Ethernet”、“NIC”、“Local”

如何在此处添加:?

$DHCP = Get-WmiObject Win32_NetworkAdapter -ComputerName $Computer -Filter '(NetConnectionID like "%Ethernet%") and (NetConnectionStatus=2)' |   ForEach-Object { $_.GetRelated('Win32_NetworkAdapterConfiguration') } 

我认为这会对你有所帮助:

$DHCP = Get-WmiObject Win32_NetworkAdapter -ComputerName $Computer -Filter 'NetConnectionStatus=2' |  
    Where-Object { $_.NetConnectionID -match 'Ethernet|NIC|Local' } |
    ForEach-Object { 
        $config = $_.GetRelated('Win32_NetworkAdapterConfiguration')
        $_ | Select-Object SystemName, Description, MACAddress, NetConnectionID, AdapterType,
                           @{Name = 'DHCPEnabled'; Expression = { $config.DHCPEnabled }}
    }

生成的 $DHCP 变量将包含如下内容:

SystemName      : Server01
Description     : Realtek PCIe GbE Family Controller
MACAddress      : AA:BB:CC:DD:EE:FF
NetConnectionID : Ethernet
AdapterType     : Ethernet 802.3
DHCPEnabled     : True