How best to return an Active Directory Computer's IP address
-
Thursday, March 01, 2012 10:30 PM
Hi there,
I recently posted a question in the directory services forum about the IPv4Address attribute of an Active Directory computer object. I can easily (I thought) get them using the activedirectory cmdlets by running:
Get-ADComputer -filter * -Properties IPv4Address | select name, IPv4Address
When I run that on the computers in my domain, I found out that about 1/3 of them don't return any value for the IPv4 address. What I found from the directory services forum is that IPv4Address is NOT an attribute of the object. It's a value that is "looked up" at the time the cmdlet is run.
And therein lies my problem. I'm trying to reconcile A records in our DNS server (which is a Linux server running BIND) with my computer objects and many names do not match.
What I need is a way to get the ACTUAL IP address from each machine with a computer object in active directory if possible. My network has Win2k8 R2 domain controllers with about 2/3 Win7 Pro and 1/3 WinXP workstations. For the most part all are running WinRM/PowerShell 2.0. Anybody have a clever way to get these IP address from the machines instead of lookup from DNS?
Thanks in advance for any help you can give me!
Troy
All Replies
-
Friday, March 02, 2012 12:36 AM
Unfortunately for you, DNS is built to be what stores the IP address. That said, you could create a GPO startup script that outputs the IP address to a text file on a share somewhere.echo %computername% ipconfig | findstr IPv4 echo ---------------
Rich Prescott | Infrastructure Architect, Windows Engineer and PowerShell blogger | MCITP, MCTS, MCP
Engineering Efficiency
@Rich_Prescott
Windows System Administration tool
AD User Creation tool -
Friday, March 02, 2012 1:11 AM
all methods will fail to determine the IP address of a computer that is powered off.
For those that are powered on, test-command might serve your purpose. You could even run a script to keep trying until it has seen all of the computers. It might be simpler to continually query AD for this info.
That said, in a DHCP environment you might find apparent duplicate IP addresses because IP addresses might have changed in the time between starting this monitoring and when it completed.
Why do you need this information? It might turn out that the reason itself makes an invalid assumption about what the information really says.
Al Dunbar
- Proposed As Answer by Yan Li_Microsoft Contingent Staff, Moderator Friday, March 02, 2012 1:48 AM
-
Friday, March 02, 2012 1:59 AM
Checkout this links...
http://gallery.technet.microsoft.com/scriptcenter/44e9fef7-a04b-40b3-bb05-97659e56e27e
http://pshscripts.blogspot.com/2009/01/get-ipaddressps1.html
Hope this helps...!!!
Thanks & Regards
Bhavik Solanki
Please click “Mark as Answer” if this post answers your question and click "Vote as Helpful if this Post helps you. -
Friday, March 02, 2012 5:10 AM
This will create a list of actual ip addresses found for each computer in the domain:
$result = @{} $computers = Get-ADComputer -Filter * | select -ExpandProperty name foreach ($computer in $computers) { try { $ipAddress = Test-Connection $computer -Count 1 -ErrorAction stop | select -ExpandProperty ipv4address $result.Add($computer, $ipAddress) } catch { Write-host "$computer offline" -ForegroundColor red $result.add($computer, 0) } } $resultGrant Ward, a.k.a. Bigteddy
- Proposed As Answer by Bhavik Solanki Friday, March 02, 2012 5:19 AM
- Marked As Answer by Yan Li_Microsoft Contingent Staff, Moderator Monday, March 05, 2012 5:42 AM
-
Monday, May 07, 2012 2:25 AM
Hi guys,
Maybe take a look at the below which retrieves the ip address from DHCP via Powershell- if your dhcp is running on windows server. Then maybe do something with AD as needed. The DHCP Wake-on-LAN Console is coded in powershell, so maybe it could be adapted to suit your purpose..
click on the link below and then click on "DCHP Wake-on-LAN console".
http://www.justcode.ca/justwindowscode/main_default_page.htm
Paul Jorgensen www.justcode.ca
- Edited by justcode_caMVP Monday, May 07, 2012 2:46 AM updated
-
Wednesday, March 13, 2013 7:49 PMIronically, DNS does not always hold a record for all AD computers. For whatever reason a computer will exist in AD U&C, but not show up in DNS, or shows up incorrectly. I've found this only seems to happen when you unjoin/rename/rejoin a computer, but I would still think that the computer would re-register itself with DNS when it joins the domain. So, finding the IP through AD would be ideal in a good number of cases.

