Detect DHCP State

by Apr 2, 2009

You can use WMI and Win32_NetworkAdapterConfiguration to determine whether a computer uses DHCP to acquire an IP address. Simply look for all instances where IPEnabled is true and DHCPEnabled is also true.

The next line will provide you with the number of network adapters using DHCP. Remember that @() wraps the result into an array so you can safely evaluate the Count property no matter how many instances are returned:

@(get-wmiobject Win32_NetworkAdapterConfiguration -filter `
'IPEnabled=true and DHCPEnabled=true' ).Count