PowerShell How-To

Use PowerShell To Create a Free IPAM Solution

You can buy a third-party tool or service. Or you can do it for free in in PowerShell.

IP address management (IPAM) is a concept that can be implemented in many ways. At its core, IPAM is simply a way to keep track of all the IP addresses in a business environment. Services such as Dynamic Host Configuration Protocol (DHCP) make this process a lot simpler -- but you'll rarely see a business track all of its IP addresses from DHCP alone. Even so, large businesses may have hundreds, if not thousands, of DHCP scopes to worry about. Even if DHCP is handing out IP addresses automatically, managing all of those scopes soon becomes a nightmare.

What medium- to large-sized businesses need is an IPAM solution. A good IPAM solution is one that enables a user to quickly query some kind of data repository (for example, a database, an Excel spreadsheet, or a CSV) to find, create and modify information about a particular IP address. IPAM solutions enable you to store more than just the IP address. You can also store information -- such as the hostname the IP is currently assigned to, the location of the host and the switch port the host is plugged into -- among other things. Storing this information enables the user to easily find all IP addresses in use at a particular location, locate any IP addresses that are free to use if needed for assigning to a new server, and so on.

There are numerous commercial solutions that set out to solve the IPAM problem. Solutions such as SolarWinds IP Address Management, Men and Mice IP Address Management Module, and GestióIP's IP Address Management Software are just a few I could quickly see were available. I'm sure all of these products do a fine job, but they've got one thing in common I'm not looking for -- they aren't free! Being commercial products, they all have a price. On the flip side, I have seen several open source IPAM tools that are free, but they aren't easily customizable and they're overkill for what I need.

I'm simply looking for some kind of small repository where I can store, perhaps, a few thousand IP addresses and common information about them -- such as associated hostname, whether or not the IP is in a DHCP scope, and the location. I need a solution that's easily customizable, so I can add another attribute later on down the road if needed. Finally, I want a solution that's easily accessible from all of my IT personnel's desktops and requires no specific software. I've got an idea -- PowerShell!

Using a PowerShell module, I can easily create functions to solve simple IPAM problems like I just described. The module I've created also doesn't involve any complicated databases or clients. The only things you need are PowerShell, the imported module and a willing staff.

This IPAM solution was designed to be as simple yet as functional as possible. This is why I've chosen to use a single shared CSV file to store all of the IP address data. Granted, this approach does not handle multiple edits at the same time, and you may run into an issue if this module is used by dozens of people at once. If you've got that much need, I recommend purchasing a commercial solution. If not, this module works great as a poor man's IPAM product.

Without further ado, let's jump into our module, called IPAddressManagement, and the steps you'll need to take to implement it.

Step 1: Download the module and place it in a shared network location where you and your team can access it.

Step 2: Create the CSV file used to store your IP addresses. Ensure the file is in a shared network location with at least a column called IPAddress. I also recommend creating a column called SubnetMask. The other attributes you'd like to assign to the IP are optional.

Step 3: Modify the module's code on line 1 to reflect the actual location of the CSV file.

Step 4: Import the module in each team member's PowerShell profile.

Step 5: Start adding IPs into your new IPAM solution!

Let's go over these steps quickly in a short tutorial.

The first step in using this module is to add some IPs into it. The following figure is a good example. It shows us adding the IP address 192.168.1.2 with a subnet mask of 255.255.255.0 for a server named MYSERVER in the location of Rome. This will work assuming you've created IPAddress, SubnetMask, Hostname, and Location fields in your CSV. The necessary functions will automatically create the field parameters you need by using dynamic parameters.

[Click on image for larger view.] 

Once you've got some IP addresses in your CSV file, a common task I've seen is figuring out an available static IP address to assign to a new server. For this reason, I created the Get-FreeIPAddress function. This function ping sweeps a particular network searching for IP addresses that don't respond to a ping. If they don't, this function will output those IP addresses. If you'd like, you can also combine this function and the New-IpAddress function to both find and record your IP addresses into the CSV file.

[Click on image for larger view.] 

You can also modify existing IP addresses with Set-IpAddress and remove IP addresses with Remove-IpAddress using similar methods.

This IPAM module is just the start. If enough work is put into it, this module could evolve into a feature-rich solution! Think about pulling in all of your DHCP scopes across all servers into your CSV -- or even scripting new server installs to assign themselves an IP address automatically using this module! I'd love to hear about any new additions you add to it. Get in touch with me on Twitter @adbertram!

 

About the Author

Adam Bertram is a 20-year veteran of IT. He's an automation engineer, blogger, consultant, freelance writer, Pluralsight course author and content marketing advisor to multiple technology companies. Adam also founded the popular TechSnips e-learning platform. He mainly focuses on DevOps, system management and automation technologies, as well as various cloud platforms mostly in the Microsoft space. He is a Microsoft Cloud and Datacenter Management MVP who absorbs knowledge from the IT field and explains it in an easy-to-understand fashion. Catch up on Adam's articles at adamtheautomator.com, connect on LinkedIn or follow him on Twitter at @adbertram or the TechSnips Twitter account @techsnips_io.


comments powered by Disqus
Most   Popular

Upcoming Training Events

0 AM
Live! 360 Orlando
November 17-22, 2024
TechMentor @ Microsoft HQ
August 11-15, 2025