AD and DNS

Hi, I am pretty new to PS but my task is this.

Get servername and description from AD and ip adr from DNS(If this is the best option). And in the end get this nice in a csv file.

This one gave me the info from AD, but then im stuck…

Get-ADComputer -Filter { OperatingSystem -Like ‘Windows Server’ } -Properties OperatingSystem, Description | sort name | Select Name, OperatingSystem, Description | Export-Csv

The reason i want this is that i want to make a customer server overview the easy way and not log in everywhere or look in a bunch of documents:)

Hi Tom,

Can’t say if getting the IP address from DNS is the best option, however try looking at the “Get-DnsServerResourceRecord”-cmdlet within the “DnsServer” module where your DNS is located (properly on your domain controller).

$ Import-Module DnsServer
$ Get-DnsServerResourceRecord -ZoneName "NameOfYourZone"

Then you could easily loop through the output from the Get-ADComputer and get the corresponding IP address of every computer from the “Get-DnsServerResourceRecord”-cmdlet.

Best regards
Stig

DNS is a great way to get IP addresses - that’s the whole point of DNS :). You can look at the Resolve-DnsName cmdlet.

Get-ADComputer -Filter { OperatingSystem -Like '*Windows Server*' } -Properties OperatingSystem, Description | sort name | Select Name, OperatingSystem, Description, @{n='IPAddress';e={ Resolve-DnsName -Name $_.Name }} | Export-Csv

That’s to get you started. Keep in mind DNS can return multiple IP addresses for a host; I’m not sure if or how you’ll want to deal with that, so this example doesn’t try. Resolve-DnsName also returns an object; you might want to extract the IP address property values instead of jamming the whole object into a property, as my example does.

Hi Tom,

Why not get the IP address directly from AD? The field name is called IPv4Address.
Also if you think the client has old Windows 2000 servers you should make the filter: “WindowsServer”.

Get-ADComputer -filter {operatingsystem -like "windows*server*"} -Properties description,ipv4address,operatingsystem | sort name | Select Name, OperatingSystem, Description,IPv4Address | Export-Csv

The only problem is that this gets only 1 IP address regardless of the number of IP’s the server actually has,

Hi,

Thank you to you all.
PowerShell rocks :slight_smile: And i realy have to spend a lot of time learning it well:) (But for now its pretty hard).

Don: You where talking about extract the IP address property value. Is that something like this: -expandproperty IPAddress? If so, where to put it. Have tried it at the end, but dont give me anything

Pays off to try, try and try again:)

This gave me what i wanted

Get-ADComputer -Filter { OperatingSystem -Like ‘Windows Server’ } -Properties OperatingSystem, Description | sort name | Select Name, OperatingSystem, Description, @{n=‘IPAddress’;e={ Resolve-DnsName -Name $_.Name | select ipaddress -ExpandProperty ipaddress}}

I implement a lot a of new customers in our datacenter. And to do this if the customer dont have an overview them self realy save me a lot of time. Thanks a lot for the starting point Don.