Created
May 1, 2015 21:01
-
-
Save bcdady/a03c0506c7e68710b8d4 to your computer and use it in GitHub Desktop.
PowerShell One-Liner: Enumerate all DHCP enabled Network Adapters via WMI / CIM, using an embedded CIM query as the -Filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Step 1, filter network adapters to those that are IP & DHCP enabled | |
# - this can only be done with the Win32_NetworkAdapterConfiguration class: | |
Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration -Filter 'IpEnabled=True AND DhcpEnabled=True' | |
# To get a unique handle to any/all network adapters matching the filtered query, retrieve only their Index propery: | |
(Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration -Filter 'IpEnabled=True AND DhcpEnabled=True').Index | |
# Using the Index property, enumerate objects in the Win32_NetworkAdapter class, with the same Index (aka DeviceID) property: | |
# - notice the prior Get-CimInstance query gets wrapped in another $(), to force returning only the resulting value into this Filter statement | |
# - I added | Format-List, because the default Table formatted results truncated the value of the .Name property | |
Get-CimInstance -ClassName Win32_NetworkAdapter -Filter "Index=$((Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration -Filter 'IpEnabled=True AND DhcpEnabled=True').Index)" | Format-List |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment