SkillPilotAI

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.
PowerShell
Get-Command -Module IpamServer `  -ErrorAction SilentlyContinue |  Measure-Object
Output
PS C:\> Get-Command -Module IpamServer -ErrorAction SilentlyContinue | Measure-Object Count    : 0

251.2 How it works

IPAM on the network
  1. 1.Admin PC runs Add-IpamDiscoveryDomain against the IPAM server

  2. 2.IPAM server asks DC1 which DHCP and DNS servers the domain has

  3. 3.DC1 answers: DHCP1, DNS1

  4. 4.Add-IpamServerInventory marks DHCP1 as Managed

  5. 5.IPAM collects scopes + leases from DHCP1 and zones from DNS1

  6. 6.Everything is stored in the WID or SQL database

IPAM only collects from servers whose ManageabilityStatus is Managed

Address hierarchy (from the PDF diagram)
  1. 1.Address space: Default

  2. 2.IP block: 10.0.0.0/8 (one big pool) -> Add-IpamBlock

  3. 3.Subnet: 10.12.0.0/16 -> Add-IpamSubnet

  4. 4.Range: 10.12.3.1 - 10.12.3.254 (often one DHCP scope) -> Add-IpamRange

  5. 5.Address: 10.12.3.5 given to one device -> Add-IpamAddress

Every level has its own Add- cmdlet

251.3 Common parameters

ParameterWhat it does
-WhatIfShows what would happen, changes nothing
-ConfirmAsks before each change
-AsJobRuns a long command as a background job
-CimSession Server01Runs the cmdlet on a remote IPAM server
-ThrottleLimit 8Max 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.
PowerShell
Add-IpamAddress -IpAddress 10.12.3.5 -PassThru
Output
PS C:\> Add-IpamAddress -IpAddress 10.12.3.5 -PassThruIpAddress        : 10.12.3.5Type             : NonVirtualizedDuplicate        : FalseExpiryStatus     : Not ExpiredMacAddress       :ManagedByService : IPAMServiceInstance  : LocalhostDeviceName       :DeviceType       : HostIpAddressState   : In-UseAssignmentType   : Static

251.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.
PowerShell
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"
Output
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.
PowerShell
Add-IpamRange -NetworkId "10.13.0.0/16" -PassThru # no parent subnet -> errorAdd-IpamRange -NetworkId "172.16.10.0/24"
Output
PS C:\> Add-IpamRange -NetworkId "172.16.10.0/24"Add-IpamRange : No subnet exists corresponding to the range.+ FullyQualifiedErrorId : WIN32 8,Add-IpamRange

251.7 Custom fields, discovery domain, server inventory

CmdletRequiredPurpose
Add-IpamCustomField-NameOwn field (team, division); free-form by default, -MultiValue for a fixed list
Add-IpamCustomValue-Name, -ValueAdds a value to a multi-value field (DivMain01 in Divisions)
Add-IpamCustomFieldAssociation-CustomFieldOne, -CustomFieldTwo, -AssociationValueLinks 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|NPSAdds a server; -ManageabilityStatus Managed = collect data
PowerShell
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 DHCP
Output
PS C:\> Add-IpamDiscoveryDomain -Name "child01.contoso.com" -DiscoverDc $False -PassThruDomainName            DiscoverDc    DiscoverDhcp    DiscoverDns child1.contoso.com    false         true            true

251.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).
PowerShell
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" }
Output
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      Disabled

251.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.
Terminal
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
Output
[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.254
Terminal
echo 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
Output
[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.