Looking for Trouble? Jump into the IP Info Weeds with PowerShell

___________________________________________________________________________________________________________________________

IMPORTANT ANNOUNCEMENT FOR OUR READERS!

AskPFEPlat is in the process of a transformation to the new Core Infrastructure and Security TechCommunity, and will be moving by the end of March 2019 to our new home at https://aka.ms/CISTechComm (hosted at https://techcommunity.microsoft.com). Please bear with us while we are still under construction!

We will continue bringing you the same great content, from the same great contributors, on our new platform. Until then, you can access our new content on either https://aka.ms/askpfeplat as you do today, or at our new site https://aka.ms/CISTechComm. Please feel free to update your bookmarks accordingly!

Why are we doing this? Simple really; we are looking to expand our team internally in order to provide you even more great content, as well as take on a more proactive role in the future with our readers (more to come on that later)! Since our team encompasses many more roles than Premier Field Engineers these days, we felt it was also time we reflected that initial expansion.

If you have never visited the TechCommunity site, it can be found at https://techcommunity.microsoft.com. On the TechCommunity site, you will find numerous technical communities across many topics, which include discussion areas, along with blog content.

NOTE: In addition to the AskPFEPlat-to-Core Infrastructure and Security transformation, Premier Field Engineers from all technology areas will be working together to expand the TechCommunity site even further, joining together in the technology agnostic Premier Field Engineering TechCommunity (along with Core Infrastructure and Security), which can be found at https://aka.ms/PFETechComm!

As always, thank you for continuing to read the Core Infrastructure and Security (AskPFEPlat) blog, and we look forward to providing you more great content well into the future!

__________________________________________________________________________________________________________________________

Fellow PFE and blogger Michael “Hilde” Hildebrand makes a great case for being able to inventory the IP configuration of your hosts – especially those that have static IP configurations (like most of your servers). For example, audit the DNS server search order (primary and secondary DNS servers) across dozens of your servers. Based on my experiences, you’re likely to find a couple of systems with an invalid (or non-optimal) setting. This can happen because DNS servers have been migrated, or retired. Or it could happen, because someone has made a mistake when entering the data.

Undoubtedly, it is to your benefit to be able to audit the IP configuration across your hosts, and proactively search for potential problems. If you administer more than 5 systems, you would benefit from an automated way to do this.

Searching the web for PowerShell code to help in this situation reveals many examples. Here’s a blog that does a great job of explaining how to build the code. Taking it to the next level, I’ve developed a multi-function script that can help you audit your configuration, and even make potential changes.

Enter the Script – IPInfoV2.ps1. Reporting IP Configuration…

The script (IPInfoV2.ps1) is attached to this blog. Feel free to review, re-cycle and re-use the code. The usual terms apply. Here’s a quick primer on using the script to report IP configuration across multiple hosts.

  • The script always requires at least one parameter (the scope of computers against which to run). Use one of the following switches to specify the scope:
    • –DCs (all DCs in the forest), OR
    • –Domain (all computers in the domain), OR
    • –Inputfile <filename> (list of computers in filename), OR
    • –BaseDN <DN> (all computers in AD container <DN> and sub-containers)
  • The script will always report to screen. (Note that all columns may not fit on the screen).
  • The script will always output results to a CSV file (IPInfo.csv), which is helpful for searching/filtering/sorting in Excel.

Example 1: Reporting IP Configuration Details for All DCs in the Forest

To report the IP configuration for every DC in the forest, simply run the script with the –DCs switch.

.\IpInfoV2.ps1 –DCs

image

image

Using the Script to “Find” Hosts That Target a Specific DNS Server…

To find which hosts are pointing to a specific IP address for Primary, Secondary or Tertiary DNS use the switch -DNSServerfind (don’t forget the scope – see above for the four scopes).

For example, to examine all the computers in the file, servers.txt, and determine which are pointing to 10.10.193.67 as a DNS server (primary, secondary or tertiary), run:

.\IPInfoV2.ps1 –inputfile “C:\scripts\servers.txt” –DNSServerFind “10.10.193.67”

image

Enter at Your Own Risk – DNS Server Replace…

Note: Be sure you test and understand the implications of making a change to the DNS Server settings on a computer before using the replace functionality of the script.

To find which hosts are pointing to a specific IP address for Primary, Secondary or Tertiary DNS, AND to change that value to a different value, use the switch -DNSServerfind AND the switch -DNSServerReplace(don’t forget the scope – see above for the four scopes).

Note: The DNSServerReplace functionality will skip any computers/interfaces that use DHCP. The assumption is that the DHCP scope will assign the DNS server.

For example, to find all domain controllers that are using 10.10.193.67 for a DNS server (primary, secondary or tertiary) AND to replace that with 10.10.193.68, run:

.\IPInfoV2.ps1 –DCs –DNSServerFind “10.10.193.67” –DNSServerReplace “10.10.193.68”

image

Add this script to your toolset, and get on top of your IP configuration – DNS server search order, WINS server search order and NetBIOS settings. Enjoy.

Update (3.April.2013):  To centralize the storage of all AskPFEPlat scripts, we are now storing them on the TechNet Script Center Repository.  This specific script can be found at the following location:

http://gallery.technet.microsoft.com/scriptcenter/IPConfig-View-or-Report-877ec0a6

 

Doug Symalla