Find Computer details in AD the easy way – Get-ADComputer

2

Hello Everybody,

I have been facing crazy DNS conflicts off late in my environment which causes a lot of headache for the users and myself as an Admin.

So I prepared a huge list of hostnames that could possibly have a DNS conflicts in the environment and thought of retrieving the associated IP addresses.

Now imagine me doing this the traditional way of resolving hostname to the IP address from nslookup to a list of hundreds of servers. That could have taken me days!! I don't even I would have had the patience of performing the activity.

That's where Powershell comes in to the picture to save me and you all the trouble.

The cmdlet that will help us find the associated IP to a computer account is Get-ADComputer.

First type Import-Module ActiveDirectory to load the Active Directory module.

Get-ADComputer has a lot of details that we will interested in. First of all, I would like to know the associated IP address and DNS hostname.

Before we go ahead and do that, let us first see what are the properties that are available to us with this cmdlet. To do so, we will pipe the output to Get-Member.

Get-ADComputer ED-EX2K10-CAH -Properties * | Get-Member

You will now be shown with the list of properties.

Next I have made a small little script that will help us perform today's demo.

$hostname = Get-Content c:\hostname.txt
$Output = foreach ($h in $hostname){
Get-ADComputer $h -Properties * | select Name,IPv4Address,DNSHostName
}
$Output | Export-csv c:\Details.csv

Let us say that you have a list of hostnames available in a text file with one hostname in each line. First we will assign that to a variable called hostname.

Next we will run for loop for each hostname in the list and filter out only the Name, IP Address and DNS Hostname.

Then we will export that to a csv file with Export-CSV cmdlet for easy editing.

That's it! It was so simple to get almost a 1000 computer's IP addresses with just four lines of code.

This was only for us to find the IP addresses. We can also find many more things with this cmdlet like when was the computer created, when was the last logon on the computer, how many bad logins were attempted, what is the Operating System on the computer etc etc.

I hope this was informative and thank you for reading!

Share.

About Author

I am Adil Arif, working as a Senior Technical Support Engineer at Rubrik as well as an independent blogger and founder of Enterprise Daddy. In my current role, I am supporting infrastructure related to Windows and VMware datacenters.

2 Comments

Leave A Reply