powershellnetwork-programmingfilterinventoryget-wmiobject

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') } 

Solution

  • 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