How do I identify all machines on network running DHCP?

goneal
goneal used Ask the Experts™
on
Afternoon -
I can get at names of machines on my network easily enough, and I can easily enough get at network adapter configuration of an individual machine to look at its nic cards, but I'm not sure how to use PowerShell to combine these two items and produce a report. The goal is a comma separated values report like the one shown below.
=======================
NAME        DHCPENABLED
COMP1     TRUE
COMP2      FALSE
=======================

The code I have currently writes to the host every WMI object for the adapters, doesn't filter out adapters that can't accept DHCP etc.

I know I need to pipe the output to narrow it down, and then pipe it again to EXPORT-CSV, but I haven't been able to figure this stuff out.

Can you help?
$STRCOMPUTER = GET-CONTENT C:\MACHINELIST.CSV
FOREACH($NAME IN $STRCOMPUTER)
{GWMI WIN32_NETWORKADAPTERCONFIGURATION -COMPUTER $STRCOMPUTER}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You could try this, but if you're targeting devices with multiple NICs like laptops you might want to play around with it a bit.

$arrComputers = GET-CONTENT C:\MACHINELIST.CSV
$arrcomputers | % {gwmi win32_networkadapterconfiguration -ComputerName $_} | ? {$_.ipenabled -eq $true -and $_.dhcpenabled -eq $true} | select dnshostname, dhcpenabled

Open in new window

leakim971Multitechnician
Top Expert 2014

Commented:
Hello goneal,

Work for me :



Import-csv C:\MACHINELIST.CSV | foreach-object { Get-WmiObject -class WIN32_NETWORKADAPTERCONFIGURATION -computername $_.computer } | Select Index,Description,DHCPEnabled | Export-CSV C:\DHCPSTATUS.txt

Open in new window

Author

Commented:
Thanks a million! I had to pipe to export-csv to get the report on something other than the Powershell host, but it did the trick.

Thanks again!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial