PowerShell IpamServer module (1/4)
The IpamServer module is the PowerShell interface to Windows IP Address Management (IPAM): one place that tracks every block, subnet, range and address in your network. This first part covers the Add-, Enable-/Disable- and Export- cmdlets, plus a Linux lab that builds a mini IPAM with ipcalc, a CSV inventory and nmap.
251.1 Why is it used?
- Without IPAM, IP plans live in spreadsheets that go stale; duplicate IPs and full subnets are found only after an outage.
- IPAM collects scopes and leases from DHCP servers and zones from DNS servers automatically.
- It shows utilization (Under / Optimal / Over) so you know which range will run out first.
- Where it runs: on the IPAM server or from the RSAT IPAM client; on the office PC the module was not installed (Count 0), so syntax and outputs come from Microsoft Learn.
Get-Command -Module IpamServer ` -ErrorAction SilentlyContinue | Measure-ObjectPS C:\> Get-Command -Module IpamServer -ErrorAction SilentlyContinue | Measure-Object Count : 0251.2 How it works
- Step 1
1.Admin PC runs Add-IpamDiscoveryDomain against the IPAM server
- Step 2
2.IPAM server asks DC1 which DHCP and DNS servers the domain has
- Step 3
3.DC1 answers: DHCP1, DNS1
- Step 4
4.Add-IpamServerInventory marks DHCP1 as Managed
- Step 5
5.IPAM collects scopes + leases from DHCP1 and zones from DNS1
- Step 6
6.Everything is stored in the WID or SQL database
IPAM only collects from servers whose ManageabilityStatus is Managed
- Step 1
1.Address space: Default
- Step 2
2.IP block: 10.0.0.0/8 (one big pool) -> Add-IpamBlock
- Step 3
3.Subnet: 10.12.0.0/16 -> Add-IpamSubnet
- Step 4
4.Range: 10.12.3.1 - 10.12.3.254 (often one DHCP scope) -> Add-IpamRange
- Step 5
5.Address: 10.12.3.5 given to one device -> Add-IpamAddress
Every level has its own Add- cmdlet
251.3 Common parameters
| Parameter | What it does |
|---|---|
| -WhatIf | Shows what would happen, changes nothing |
| -Confirm | Asks before each change |
| -AsJob | Runs a long command as a background job |
| -CimSession Server01 | Runs the cmdlet on a remote IPAM server |
| -ThrottleLimit 8 | Max concurrent operations |
| -Verbose, -ErrorAction, -OutVariable ... | Normal PowerShell common parameters |
251.4 Add-IpamAddress
- Records one IP in IPAM; only -IpAddress is required.
- Defaults: ManagedByService IPAM, DeviceType Host, AssignmentType Static, IpAddressState In-Use.
- Device details: -DeviceName, -MacAddress, -Owner, -AssetTag, -SerialNumber, -Description.
- -ExpiryDate makes IPAM alert the admin; -Reservation* options store DHCP reservation details.
- -CustomConfiguration "Name=Value;..." attaches custom field values.
Add-IpamAddress -IpAddress 10.12.3.5 -PassThruPS C:\> Add-IpamAddress -IpAddress 10.12.3.5 -PassThruIpAddress : 10.12.3.5Type : NonVirtualizedDuplicate : FalseExpiryStatus : Not ExpiredMacAddress :ManagedByService : IPAMServiceInstance : LocalhostDeviceName :DeviceType : HostIpAddressState : In-UseAssignmentType : Static251.5 Add-IpamAddressSpace, Add-IpamBlock, Add-IpamSubnet
- Address space is for multi-tenant data centers; -Name required. A customer space also needs -AssociatedProviderAddressSpace and -IsolationMethod (e.g. NVGRE).
- Add-IpamBlock needs -NetworkId in CIDR; without -StartIPAddress/-EndIPAddress it uses the first and last address of the network.
- A public block needs -Rir (e.g. "APNIC").
- Add-IpamSubnet needs both -Name and -NetworkId; -VlanId takes an array of VLANs.
- Overlapping : False means the subnet does not overlap any other subnet.
Add-IpamAddressSpace -Name "ProviderAddSpace01" -ProviderAddressSpace Add-IpamBlock -NetworkId "10.0.0.0/8" ` -Description "IP block for Contoso" -PassThru Add-IpamSubnet -Name "Contoso_2" ` -NetworkId "10.12.0.0/16" ` -VlanId 13,10 -PassThru # custom metadata as Name=Value pairs-CustomConfiguration "Country=United States;ADSite=Site01"PS C:\> Add-IpamBlock -NetworkId "10.0.0.0/8" -Description "IP block for Contoso" -PassThruUtilization : UnderNetworkId : 10.0.0.0/8StartAddress : 10.0.0.0EndAddress : 10.255.255.255Rir :TotalAddresses : 16777216AddressCategory : PrivateDescription : IP block for Contoso PS C:\> Add-IpamSubnet -Name "Contoso_2" -NetworkId "10.12.0.0/16" -VlanId 13,10 -PassThruName : Contoso_2NetworkId : 10.12.0.0/16NetworkType : NonVirtualizedOverlapping : FalseProviderAddressSpace : DefaultVlanId : {13, 10}251.6 Add-IpamRange
- Adds part of a subnet; -NetworkId is required.
- Only 10.13.0.0/16 given -> start 10.13.0.1 and end 10.13.255.254 are set automatically.
- Rule: a range needs a parent subnet, otherwise you get an error; -CreateSubnetIfNotFound creates it.
- Other settings: -DnsServer, -DnsSuffix, -Gateway "10.10.5.1/Automatic", -ReservedAddress, -VIP (load balancer IPs), -UtilizationCalculation Auto|UserSpecified.
Add-IpamRange -NetworkId "10.13.0.0/16" -PassThru # no parent subnet -> errorAdd-IpamRange -NetworkId "172.16.10.0/24"PS C:\> Add-IpamRange -NetworkId "172.16.10.0/24"Add-IpamRange : No subnet exists corresponding to the range.+ FullyQualifiedErrorId : WIN32 8,Add-IpamRange251.7 Custom fields, discovery domain, server inventory
| Cmdlet | Required | Purpose |
|---|---|---|
| Add-IpamCustomField | -Name | Own field (team, division); free-form by default, -MultiValue for a fixed list |
| Add-IpamCustomValue | -Name, -Value | Adds a value to a multi-value field (DivMain01 in Divisions) |
| Add-IpamCustomFieldAssociation | -CustomFieldOne, -CustomFieldTwo, -AssociationValue | Links values of two fields as pairs (Storage:Site01) |
| Add-IpamDiscoveryDomain | -Name (AD FQDN) | Domain where IPAM looks for servers; -DiscoverDc/-DiscoverDhcp/-DiscoverDns default True |
| Add-IpamServerInventory | -Name, -ServerType DC|DNS|DHCP|NPS | Adds a server; -ManageabilityStatus Managed = collect data |
Add-IpamCustomValue -Name "Divisions" -Value "DivMain01" -PassThru Add-IpamCustomFieldAssociation ` -CustomFieldOne "VmmLogicalNetwork" ` -CustomFieldTwo "NetworkSite" ` -AssociationValue "Storage:Site01","Public:Site03" -PassThru Add-IpamDiscoveryDomain -Name "child01.contoso.com" ` -DiscoverDc $False -PassThru Add-IpamServerInventory -Name "Dhcp1.Contoso.com" -ServerType DHCPPS C:\> Add-IpamDiscoveryDomain -Name "child01.contoso.com" -DiscoverDc $False -PassThruDomainName DiscoverDc DiscoverDhcp DiscoverDns child1.contoso.com false true true251.8 Capability and Export cmdlets
- Enable-/Disable-IpamCapability: today there is only one capability, IpAddressTracking.
- Disabling asks Confirm (-Force skips it); old audit data stays, new data is not collected.
- Export-IpamAddress / Export-IpamRange write CSV; -AddressFamily IPv4|IPv6 is required.
- -Path names the file, -Force overwrites, -PassThru also returns objects (pipe to Where-Object).
Disable-IpamCapability -Capability IpAddressTrackingGet-IpamCapability Export-IpamAddress -AddressFamily IPv4 -Path "C:\Addresses_v4.csv"Export-IpamRange -AddressFamily IPv6 -Path "C:\Ranges_v6.csv" -Force # over-utilized ranges onlyExport-IpamRange -AddressFamily IPv4 -PassThru | Where-Object -FilterScript { $_.Utilization -Eq "Over" }PS C:\> Disable-IpamCapability -Capability IpAddressTrackingConfirmDisabling IpAddressTracking. Do you want to continue?.[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): yPS C:\> Get-IpamCapabilityName Status---- ------IpAddressTracking Disabled251.9 Lab: a mini IPAM on Linux
- Linux equivalent (the module runs only on Windows); container ipam1 = 192.168.251.5 on n251-lan 192.168.251.0/24.
- ipcalc = block, ipcalc -S 24 = split into subnets, sipcalc = usable range.
- A CSV with custom fields type and owner acts as the address inventory; awk queries it.
- Scan only your own lab subnet, never the office network.
ipcalc 192.168.248.0/22 # blockipcalc -S 24 192.168.248.0/22 # block -> /24 subnetssipcalc 192.168.251.0/24 # subnet -> usable range[ipam1]$ sipcalc 192.168.251.0/24Network address - 192.168.251.0Network mask - 255.255.255.0Broadcast address - 192.168.251.255Addresses in network - 256Usable range - 192.168.251.1 - 192.168.251.254echo 192.168.251.40,cam1,camera,ravi,in-use >> /ipam/inventory.csvawk -F, '$4 == "ravi"' /ipam/inventory.csvawk -F, 'NR > 1 { n[$3]++ } END { for (t in n) print t, n[t] }' /ipam/inventory.csv | sort # discovery: only our own lab subnetnmap -sn -n 192.168.251.0/24 -oG - | awk '/Up$/ { print $2 }' > /ipam/up.txtawk -F, 'NR == FNR { up[$1] = 1; next } FNR > 1 { s[$1] = 1; print $1, $2, ($1 in up ? "UP" : "NOT-SEEN") } END { for (i in up) if (!(i in s)) print i, "-", "NOT-IN-INVENTORY" }' \ /ipam/up.txt /ipam/inventory.csv[ipam1]$ awk -F, '$4 == "ravi"' /ipam/inventory.csv192.168.251.20,db1,server,ravi,in-use192.168.251.40,cam1,camera,ravi,in-use[ipam1]$ awk -F, 'NR > 1 { n[$3]++ } END { ... }' | sortcamera 1gateway 1printer 1server 3[ipam1]$ awk -F, '...' /ipam/up.txt /ipam/inventory.csv192.168.251.1 gw1 UP192.168.251.5 ipam1 UP192.168.251.10 web1 UP192.168.251.20 db1 UP192.168.251.30 printer1 UP192.168.251.40 cam1 NOT-SEEN192.168.251.45 - NOT-IN-INVENTORY- cam1 NOT-SEEN = stale record to check; .45 NOT-IN-INVENTORY = unknown device to add.
251.10 Common mistakes
- Thinking Add-IpamAddress gives the device an IP: it only keeps a record and does not create a DHCP reservation (use Add-DhcpServerv4Reservation).
- Adding a range before its subnet: error "No subnet exists corresponding to the range."
- Adding servers to the inventory but leaving them Unspecified: no data is collected until they are Managed.
- Running nmap against networks you do not own.
251.11 Interview tips
- Onboarding a new network: Add-IpamBlock -> Add-IpamSubnet -> Add-IpamRange, then Add-IpamDiscoveryDomain + Add-IpamServerInventory (Managed).
- Check capacity with Export-IpamRange -PassThru | Where-Object Utilization -Eq Over.
- Hierarchy to remember: address space > block > subnet > range > address.
- IPAM is a record and monitoring system, not a DHCP server.