简体   繁体   中英

Filtering Names: Get-WmiObject Win32_NetworkAdapter

as a part of my inventory script i want to to add query of DHCP enabeld or not i need to sample network cards starts with: "Ethernet", "NIC" , "Local"

how do i add it here:?

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

I think this will help you on your way:

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

The resulting $DHCP variable will contain something like:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM