locked
get IPs and assigned computer name in domain. RRS feed

  • Question

  • Hopefully I am stating this correctly, I am novice with networking and powershell, but am learning.

    I need to write a script that loops through an IP range and returns the computer names assigned to that IP.  We need a free IP for a SQL Server that we want to install.

    This is all new to me...  so a 100 level explanation would be best.  I am a self taught SQL Server and BI developer and never really took a networking class, but I just realized this is a weakness and I am dedicated to learning.  The other area I want to learn is powershell and how I can use it for SQL DBA tasks and BI tasks.

    Thanks,

    Mike

    Tuesday, November 6, 2018 3:33 PM

Answers

All replies

  • You can't find a free IP that way.  One or more computers may be offline and you can get a bad IP.

    Look at your DNS server to see which computers and IPs are in use.  Also remember that printers and other devices may be using IPs and may not be online when you test.  The DNS records are the easiest method.

    You can easily export IPs and names from the DNS console to a CSV file or dump records as text using DNSCMD.


    \_(ツ)_/

    Tuesday, November 6, 2018 3:49 PM
  • Forgot.

    You can dump all records with PowerShell:

    Get-DnsServerResourceRecord-ZoneName "contoso.com"


    \_(ツ)_/

    Tuesday, November 6, 2018 3:51 PM
  • so say our domain is abcd...   my login is abcd\mike.  Can I run this in powershell from my desktop?  when I ran

    Get-DnsServerResourceRecord-ZoneName "abcd" I get big ugly red error.

    Tuesday, November 6, 2018 4:04 PM
  • You need to run Get-DnsServerResourceRecord from the domain controller.

    Another option:

    Get-AdComputer -filter * -properties * | select name,ipv4address
    
    ### Get-AdComputer -filter * -properties * | select name,ipv4address | Export-Csv .\server_ip.csv -NoType
    

    Tuesday, November 6, 2018 4:09 PM
  • Agreed . . . but with the caveat that "it's complicated". If DHCP is involved, and scavenging is (or isn't) enabled on the zone, there can be duplicated IP addresses, leased IP addresses that have expired, etc. You'd also have to get the records from every zone (client vs. servers in different zones, for example, or even machines running different O/S may be segregated in different zones).

    You might want to limit the record types you ask for, too. Getting A and AAAA records are what you really want, and most places have no idea that they're even using IPv6, or just don't bother assigning static (or DHCP) IPv6 addresses.

     

    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Tuesday, November 6, 2018 4:14 PM
  • You have to run it on a 2012 or later server with DNS installed.


    \_(ツ)_/

    Tuesday, November 6, 2018 4:18 PM
  • The major agreement here is what we see everywhere.  Maintaining an accurate list of IPs in use is a pain without a good tool.

    MS has a tool that allows us to document and mange IPs but still takes a bit of effort to keep clean.

    .

    IPAM (IP Address Management Tool)  (Comes with PowerShell Module)

    https://blogs.technet.microsoft.com/canitpro/2013/08/15/step-by-step-setup-windows-server-2012-ipam-in-your-environment/

    This is the 2012 add-in.  2016 comes with IPAM.  There are also many third parties that make IPAM available.  All including Microsoft can dump IPs in use and/or IPs available to a spreadsheet.


    \_(ツ)_/



    • Edited by jrv Tuesday, November 6, 2018 4:27 PM
    Tuesday, November 6, 2018 4:26 PM
  • You need to run Get-DnsServerResourceRecord from the domain controller.

    Another option:

    Get-AdComputer -filter * -properties * | select name,ipv4address
    
    ### Get-AdComputer -filter * -properties * | select name,ipv4address | Export-Csv .\server_ip.csv -NoType


    This does not account for printer, gateways and other devices in the domain.

    \_(ツ)_/

    Wednesday, November 7, 2018 3:26 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Tuesday, November 27, 2018 2:19 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Tuesday, December 4, 2018 2:37 AM