2021-03-30 16:34:25 +02:00
|
|
|
|
<#
|
2020-03-23 12:18:01 -04:00
|
|
|
|
.NOTES
|
|
|
|
|
|
===========================================================================
|
|
|
|
|
|
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
|
|
|
|
|
|
Created on: 3/19/2020 11:50
|
|
|
|
|
|
Created by: Claussen
|
|
|
|
|
|
Organization: NEOnet
|
|
|
|
|
|
Filename: Get-NetboxIPAMAvailableIP.ps1
|
|
|
|
|
|
===========================================================================
|
|
|
|
|
|
.DESCRIPTION
|
|
|
|
|
|
A description of the file.
|
|
|
|
|
|
#>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Get-NetboxIPAMAvailableIP {
|
2021-03-30 16:34:25 +02:00
|
|
|
|
<#
|
2020-03-23 12:18:01 -04:00
|
|
|
|
.SYNOPSIS
|
|
|
|
|
|
A convenience method for returning available IP addresses within a prefix
|
2021-03-30 16:34:25 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
.DESCRIPTION
|
|
|
|
|
|
By default, the number of IPs returned will be equivalent to PAGINATE_COUNT. An arbitrary limit
|
|
|
|
|
|
(up to MAX_PAGE_SIZE, if set) may be passed, however results will not be paginated
|
2021-03-30 16:34:25 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
.PARAMETER Prefix_ID
|
|
|
|
|
|
A description of the Prefix_ID parameter.
|
2021-03-30 16:34:25 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
.PARAMETER Limit
|
|
|
|
|
|
A description of the Limit parameter.
|
2021-03-30 16:34:25 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
.PARAMETER Raw
|
|
|
|
|
|
A description of the Raw parameter.
|
2021-03-30 16:34:25 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
.PARAMETER NumberOfIPs
|
|
|
|
|
|
A description of the NumberOfIPs parameter.
|
2021-03-30 16:34:25 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
.EXAMPLE
|
2021-07-23 16:24:27 +02:00
|
|
|
|
Get-NetboxIPAMAvailableIP -Prefix_ID (Get-NetboxIPAMPrefix -Prefix 192.0.2.0/24).id
|
|
|
|
|
|
|
|
|
|
|
|
Get (Next) Available IP on the Prefix 192.0.2.0/24
|
|
|
|
|
|
|
|
|
|
|
|
.EXAMPLE
|
|
|
|
|
|
Get-NetboxIPAMAvailableIP -Prefix_ID 2 -NumberOfIPs 3
|
|
|
|
|
|
|
|
|
|
|
|
Get 3 (Next) Available IP on the Prefix 192.0.2.0/24
|
2021-03-30 16:34:25 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
.NOTES
|
|
|
|
|
|
Additional information about the function.
|
|
|
|
|
|
#>
|
2021-03-30 16:34:25 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
[CmdletBinding()]
|
|
|
|
|
|
param
|
|
|
|
|
|
(
|
|
|
|
|
|
[Parameter(Mandatory = $true,
|
2021-03-30 16:34:25 +02:00
|
|
|
|
ValueFromPipelineByPropertyName = $true)]
|
2020-03-23 12:18:01 -04:00
|
|
|
|
[Alias('Id')]
|
2021-03-30 16:34:25 +02:00
|
|
|
|
[int]$Prefix_ID,
|
|
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
[Alias('NumberOfIPs')]
|
2021-03-30 16:34:25 +02:00
|
|
|
|
[int]$Limit,
|
|
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
[switch]$Raw
|
|
|
|
|
|
)
|
2021-03-30 16:34:25 +02:00
|
|
|
|
|
|
|
|
|
|
process {
|
|
|
|
|
|
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes', $Prefix_ID, 'available-ips'))
|
|
|
|
|
|
|
|
|
|
|
|
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'prefix_id'
|
|
|
|
|
|
|
|
|
|
|
|
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
|
|
|
|
|
|
|
|
|
|
|
|
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
|
|
|
|
|
}
|
2020-03-23 12:18:01 -04:00
|
|
|
|
}
|