PowerShell IpamServer module (4/4)
The last part of the IpamServer module: the Set- cmdlets that change existing IPAM records (addresses, spaces, blocks, subnets, ranges), the IPAM server's own settings (configuration, database, discovery, thresholds, inventory) and Update-IpamServer after an OS upgrade. The lab updates CSV records with awk/sed and watches a utilization threshold get crossed.
254.1 Why is it used?
- Networks change: a VM moves to VMM, a subnet gets a new VLAN, a server gets a new owner; the records must follow.
- Thresholds decide when IPAM shows Under/Over, so alerts fire at the right time.
- Server settings (port, database, discovery, inventory) are tuned with Set- cmdlets.
- Office PC: module not installed (Count 0); Set- cmdlets change data, so the office IPAM/AD was never touched.
254.2 How it works
- Step 1
1.Admin PC sends Set-IpamAddress to the IPAM server
- Step 2
2.IPAM updates the record in its own database
- Step 3
3.The device's own IP configuration does NOT change
- Step 4
4.After Set-IpamDatabase, IPAM keeps data on SQL Server ContosoDB04 (MSSQL, port 1433)
- Step 5
5.Set-IpamServerInventory -ManageabilityStatus Managed on Dhcp01
- Step 6
6.IPAM now collects scopes + leases from Dhcp01
254.3 Set-IpamAddress and Set-IpamAddressSpace
- Common pattern: Get-IpamAddress | Set-IpamAddress ... -PassThru.
- -NewManagedByService / -NewServiceInstance hand the address to another service (docs: 172.16.10.10 to VMM, DeviceType VM).
- Direct fields: -Owner, -Description, -DeviceName, -AssetTag, -MacAddress, -SerialNumber, -ClientId, -Duid/-Iaid.
- -ExpiryDate (expiry alert), -Reservation* (DHCP reservation details), -NewIPAddress, -NewNetworkType + -NewAddressSpace (move between spaces).
- Set-IpamAddressSpace renames (OneDataCenter -> MainDataCenter) and sets -Tenant, -VmNetwork, -IsolationMethod, -AssociatedProviderAddressSpace.
Get-IpamAddress -IpAddress 172.16.10.10 | Set-IpamAddress -NewManagedByService "VMM" ` -NewServiceInstance "vmm1.contoso.com" -DeviceType "VM" -PassThru Set-IpamAddress -IpAddress 172.16.10.10 -NetworkType NonVirtualized ` -NewNetworkType Provider -NewAddressSpace MainDataCenter -PassThru | Format-List IpAddress, NetworkType, ProviderAddressSpace, CustomerAddressSpace Set-IpamAddressSpace -Name "OneDataCenter" -NewName "MainDataCenter" -PassThruIpAddress : 172.16.10.10NetworkType : ProviderProviderAddressSpace : MainDataCenterCustomerAddressSpace :254.4 Set-IpamAddressUtilizationThreshold
- Two main options: -UnderUtilizationThreshold and -OverUtilizationThreshold (percent).
- These limits decide whether a block or range shows Under, Optimal or Over.
- Docs: over 80 -> 70, then under 20 -> 40.
Set-IpamAddressUtilizationThreshold -OverUtilizationThreshold 70 -PassThruSet-IpamAddressUtilizationThreshold -UnderUtilizationThreshold 40 -PassThruPS C:\> Set-IpamAddressUtilizationThreshold -OverUtilizationThreshold 70 -PassThruUnderUtilizationThreshold OverUtilizationThreshold------------------------- ------------------------20 70PS C:\> Set-IpamAddressUtilizationThreshold -UnderUtilizationThreshold 40 -PassThruUnderUtilizationThreshold OverUtilizationThreshold------------------------- ------------------------40 70254.5 Set-IpamBlock, Set-IpamSubnet, Set-IpamRange
| Cmdlet | Select by | Typical changes |
|---|---|---|
| Set-IpamBlock | Pipe from Get-IpamBlock (e.g. -MappingToParentBlock) | -Description for all child blocks; -NewNetworkId/-NewStartIPAddress/-NewEndIpAddress (resets utilization trend, asks confirm) |
| Set-IpamSubnet | -NetworkId (required) | /16 -> /17 via -NewNetworkId, -Name rename, -VlanId, -Owner, -NetworkSite, -AddCustomConfiguration |
| Set-IpamRange | -StartIPAddress + -EndIPAddress | -NewManagedByService, -NewStart/EndIPAddress, -Gateway/-DnsServer/-WinsServer, -ReservedAddress, -VIP, -UtilizationCalculation UserSpecified + -UtilizedAddresses |
Get-IpamBlock -MappingToParentBlock $Parent | Set-IpamBlock -Description "IP Blocks assigned to Site01" -PassThru Set-IpamSubnet -NetworkId 10.10.1.0/16 -NetworkType NonVirtualized ` -NewNetworkId 10.10.1.0/17Get-IpamSubnet -AddressFamily IPv4 | where {$_.Name -Like "Site*"} | Set-IpamSubnet -AddCustomConfiguration "ADSite=Site01" -PassThru | Format-List Name, NetworkId, CustomConfiguration Get-IpamRange -StartIPAddress 10.12.1.1 -EndIPAddress 10.12.1.254 | Set-IpamRange -NewManagedByService VMM ` -NewServiceInstance "vmm1.contoso.com" -PassThruName : Site01_2NetworkId : 10.20.1.0/24CustomConfiguration : ADSite=Site01;Name : Site01_3NetworkId : 10.20.2.0/24CustomConfiguration : ADSite=Site01; Overlapping : FalseNetworkID : 10.12.0.0/16StartAddress : 10.12.1.1EndAddress : 10.12.1.254ManagedByService : VMMServiceInstance : vmm1.contoso.comNetworkType : NonVirtualized254.6 Server settings: configuration, database, discovery, custom field association
- Set-IpamConfiguration (docs example uses Set-IpamServerConfiguration -Port 45000): management port, -ProvisioningMethod Automatic|Manual, -GpoPrefix, -HmacKey / -RefreshHmacKey.
- Set-IpamDatabase points IPAM at SQL Server; it does NOT move data, and after success IPAM cannot go back to WID.
- Set-IpamDiscoveryDomain -DiscoverDc $False: DCs are not discovered, DNS/DHCP stay True.
- Set-IpamCustomFieldAssociation: -AddAssociateValue / -RemoveAssociationValue, each pair "value1:value2".
| Point | Move-IpamDatabase | Set-IpamDatabase |
|---|---|---|
| Copies data | Yes, all IPAM data | No |
| Result | IPAM on the new SQL DB with old data | IPAM settings now point to the given SQL DB |
| Go back to WID | No | No (docs warning) |
Set-IpamServerConfiguration -Port 45000 -PassThru -ForceSet-IpamConfiguration -ProvisioningMethod Automatic -GpoPrefix "IPAM" Set-IpamDatabase -DatabaseServer "ContosoDB04" -DatabaseName "IpamData01" ` -DatabasePort 1433 -DatabaseAuthType Windows Set-IpamDiscoveryDomain -Name "contoso.com" -DiscoverDc $False -PassThruSet-IpamCustomFieldAssociation -CustomFieldOne "VmmLogicalNetwork" ` -CustomFieldTwo "NetworkSite" -AddAssociateValue "Storage:Site03" ` -RemoveAssociationValue "Public:Site03" -PassThruPS C:\> Set-IpamDatabase -DatabaseServer "ContosoDB04" -DatabaseName "IpamData01" -DatabasePort 1433 -DatabaseAuthType WindowsConfirmUpdating IPAM database settings to use an MsSql database. If the configuration is successful, IPAM cannot bereconfigured to use Windows Internal Database. The cmdlet will verify that the database specified is reachable andcompatible with Ipam version. Do you want to continue?[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): YPS C:\> Get-IpamDatabaseDatabaseType : MSSQLDatabaseServer : ContosoDB04DatabaseName : IpamData01DatabasePort : 1433DatabaseAuthType : Windows CustomFieldOne : VmmLogicalNetworkCustomFieldTwo : NetworkSiteAssociationValue : {Storage:Site01, Storage:Site03, Storage:Site02}254.7 Set-IpamServerInventory and Update-IpamServer
- Set-IpamServerInventory -ManageabilityStatus Unspecified|Unmanaged|Managed (docs: Dhcp01 -> Managed).
- -ServerType DC|DNS|DHCP|NPS sets roles; -NewName is checked by resolving it to an IP.
- Update-IpamServer: run after an OS upgrade to apply settings and database schema changes.
- -DeleteSystemCheckFailureRows deletes rows that fail the system check so the upgrade does not stop.
Set-IpamServerInventory -Name "Dhcp01" -ManageabilityStatus Managed -PassThruUpdate-IpamServerUpdate-IpamServer -DeleteSystemCheckFailureRowsPS C:\> Update-IpamServerUpgrading IPAM Server. As a part of upgrade, any changes in IPAM Server settings & configuration will be applied. Any requisite changes to database schema changes will be made. Do you want to continue?[Y]Yes [N]No [S]Suspend [?]Help (default is "Y"): Y254.8 Lab: update records and cross a threshold
- Linux equivalent on n254-lan 192.168.254.0/24; scan only the own lab.
- awk changes one row (app1: VM/ravi -> Host/asha, "billing app") = Set-IpamAddress idea.
- sed changes VLAN 10 -> 20 and pune-dc1 -> pune-dc2 on one subnet line = Set-IpamSubnet idea.
- nmap + awk with UNDER=20 OVER=80 = threshold idea; re-scan after cache1 starts = Update/inventory idea.
awk -F, -v OFS=, '$1=="192.168.254.19"{ $3="Host"; $4="asha"; $5="billing app"} 1' \ /tmp/addresses.csv > /tmp/a.new && mv /tmp/a.new /tmp/addresses.csv sed -i \ -e '/^192.168.254.0\/24,/s/,10,/,20,/' \ -e '/^192.168.254.0\/24,/s/dc1$/dc2/' \ /tmp/subnets.csv[ipam]$ column -t -s, /tmp/addresses.csvIpAddress DeviceName DeviceType Owner Description192.168.254.17 web1 Host asha web server192.168.254.18 db1 Host ravi database192.168.254.19 app1 Host asha billing app192.168.254.20 print1 Printer student floor printer[ipam]$ cat /tmp/subnets.csvNetworkId,Name,VlanId,Location192.168.254.0/24,SiteA_lab,20,pune-dc2- Step 1
1.ipam box (.10) sends ARP who-has .17-.22 over the n254-lan bridge
- Step 2
2.web1, db1, app1, print1 reply: 4 of 6 used = 66.67% -> Ok
- Step 3
3.New server cache1 starts on .21
- Step 4
4.Re-scan: cache1 replies too
- Step 5
5.5 of 6 used = 83.33% -> Over (above 80)
- Step 6
6.comm adds .21 to the inventory CSV
nmap -sn -n -oG - 192.168.254.16/29 | awk '/Up$/{print $2}' | sort -t. -k4,4n > /tmp/scan1.txtUNDER=20 OVER=80awk -v u=$UNDER -v o=$OVER 'END{ p=NR*100/6 s=(p>o)?"Over":(p<u)?"Under":"Ok" printf "range .17-.22: %d of 6 ...", NR, p, s, u, o}' /tmp/scan1.txt # after cache1 starts on .21nmap -sn -n -oG - 192.168.254.16/29 | awk '/Up$/{print $2}' | sort -t. -k4,4n > /tmp/scan2.txtdiff /tmp/scan1.txt /tmp/scan2.txtcomm -13 /tmp/scan1.txt /tmp/scan2.txt | while read ip; do echo "$ip,cache1,Host,asha,new cache"; done >> /tmp/addresses.csv[ipam]$ UNDER=20 OVER=80; awk ... /tmp/scan1.txtrange .17-.22: 4 of 6 used = 66.67% -> Ok (under 20, over 80)[ipam]$ UNDER=20 OVER=80; awk ... /tmp/scan2.txtrange .17-.22: 5 of 6 used = 83.33% -> Over (under 20, over 80)[ipam]$ comm -13 ... >> /tmp/addresses.csv; column -t -s, /tmp/addresses.csvIpAddress DeviceName DeviceType Owner Description192.168.254.19 app1 Host asha billing app192.168.254.20 print1 Printer student floor printer192.168.254.21 cache1 Host asha new cache254.9 Common mistakes
- Thinking Set-IpamAddress changes the IP on the device: it only updates the IPAM DB record; change the device separately and verify with a scan or Get-.
- Using Set-IpamDatabase expecting a data move: it only repoints settings (use Move-IpamDatabase to copy data).
- Changing a block's NetworkId without knowing it resets the utilization trend.
- Forgetting Update-IpamServer after an OS upgrade.
254.10 Interview tips
- Range at 83% shows Over but 90% is fine: Set-IpamAddressUtilizationThreshold -OverUtilizationThreshold 90 -PassThru.
- Subnet VLAN changed + new server owner: Set-IpamSubnet -NetworkId .. -VlanId -Owner, then Get-IpamAddress | Set-IpamAddress -Owner -PassThru.
- Always use -PassThru to confirm the new object.
- Set- = change an existing record; Add- = new record; Remove- = delete.