APICalls/Get-NetBoxIPAM.ps1
function Get-NetBoxIPAM { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [ValidateSet('VLANs', 'Prefixes', 'VRFS', 'VLAN-Groups', 'Services', 'Service-Templates', 'Route-Targets', 'Roles', 'RIRS', 'IP-Ranges', 'IP-Addresses', 'FHRP-Groups', 'FHRP-Group-Assigments', 'Aggregates', 'ASNS', 'ASN-Ranges' )] [String]$QueryObject, [String]$ID, [switch]$ShowQuery ) begin { $Method = 'Get' $APICall = 'ipam/' $APICall += $QueryObject.ToLower() + '/' if ($ID) { $APICall += "$ID/" } $Data = @() } process { try { $count = 0 do { if ($PagedData) { $PagedAPICall = "${APICall}?limit=50&offset=$Count" } else { # first request $PagedAPICall = "${APICall}" } if ($ShowQuery) { Write-Host $PagedAPICall } $PagedData = Invoke-NetBoxRestMethod -APICall $PagedAPICall -Method $Method # combine the previous object with the new entries try { if ($PagedData.results) { $Data += $PagedData.results } else { $Data += $PagedData } } catch { Write-Error "Unable to combine data. $_" } $count += 50 } while ($PagedData.next) } catch { throw } } end { return $Data } } |