2021-07-23 22:06:42 +02:00
|
|
|
|
<#
|
2021-03-25 16:52:08 -04:00
|
|
|
|
.NOTES
|
|
|
|
|
|
===========================================================================
|
|
|
|
|
|
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2021 v5.8.186
|
|
|
|
|
|
Created on: 2021-03-23 13:54
|
|
|
|
|
|
Created by: Claussen
|
|
|
|
|
|
Organization: NEOnet
|
|
|
|
|
|
Filename: Set-NetboxIPAMPrefix.ps1
|
|
|
|
|
|
===========================================================================
|
|
|
|
|
|
.DESCRIPTION
|
|
|
|
|
|
A description of the file.
|
|
|
|
|
|
#>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Set-NetboxIPAMPrefix {
|
|
|
|
|
|
[CmdletBinding(ConfirmImpact = 'Medium',
|
|
|
|
|
|
SupportsShouldProcess = $true)]
|
|
|
|
|
|
param
|
|
|
|
|
|
(
|
|
|
|
|
|
[Parameter(Mandatory = $true,
|
|
|
|
|
|
ValueFromPipelineByPropertyName = $true)]
|
|
|
|
|
|
[uint16[]]$Id,
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2021-03-25 16:52:08 -04:00
|
|
|
|
[string]$Prefix,
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2021-03-25 16:52:08 -04:00
|
|
|
|
[string]$Status,
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2021-03-25 16:52:08 -04:00
|
|
|
|
[uint16]$Tenant,
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2021-03-25 16:52:08 -04:00
|
|
|
|
[uint16]$Site,
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2021-03-25 16:52:08 -04:00
|
|
|
|
[uint16]$VRF,
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2021-03-25 16:52:08 -04:00
|
|
|
|
[uint16]$VLAN,
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2021-03-25 16:52:08 -04:00
|
|
|
|
[object]$Role,
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2021-03-25 16:52:08 -04:00
|
|
|
|
[hashtable]$Custom_Fields,
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2021-03-25 16:52:08 -04:00
|
|
|
|
[string]$Description,
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2021-03-25 16:52:08 -04:00
|
|
|
|
[switch]$Is_Pool,
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2021-03-25 16:52:08 -04:00
|
|
|
|
[switch]$Force
|
|
|
|
|
|
)
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2021-03-25 16:52:08 -04:00
|
|
|
|
begin {
|
|
|
|
|
|
# Write-Verbose "Validating enum properties"
|
|
|
|
|
|
# $Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses', 0))
|
|
|
|
|
|
$Method = 'PATCH'
|
2021-07-23 22:06:42 +02:00
|
|
|
|
#
|
2021-03-25 16:52:08 -04:00
|
|
|
|
# # Value validation
|
|
|
|
|
|
# $ModelDefinition = GetModelDefinitionFromURIPath -Segments $Segments -Method $Method
|
|
|
|
|
|
# $EnumProperties = GetModelEnumProperties -ModelDefinition $ModelDefinition
|
2021-07-23 22:06:42 +02:00
|
|
|
|
#
|
2021-03-25 16:52:08 -04:00
|
|
|
|
# foreach ($Property in $EnumProperties.Keys) {
|
|
|
|
|
|
# if ($PSBoundParameters.ContainsKey($Property)) {
|
|
|
|
|
|
# Write-Verbose "Validating property [$Property] with value [$($PSBoundParameters.$Property)]"
|
|
|
|
|
|
# $PSBoundParameters.$Property = ValidateValue -ModelDefinition $ModelDefinition -Property $Property -ProvidedValue $PSBoundParameters.$Property
|
|
|
|
|
|
# } else {
|
|
|
|
|
|
# Write-Verbose "User did not provide a value for [$Property]"
|
|
|
|
|
|
# }
|
|
|
|
|
|
# }
|
2021-07-23 22:06:42 +02:00
|
|
|
|
#
|
2021-03-25 16:52:08 -04:00
|
|
|
|
# Write-Verbose "Finished enum validation"
|
|
|
|
|
|
}
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2021-03-25 16:52:08 -04:00
|
|
|
|
process {
|
|
|
|
|
|
foreach ($PrefixId in $Id) {
|
|
|
|
|
|
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes', $PrefixId))
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2021-03-25 16:52:08 -04:00
|
|
|
|
Write-Verbose "Obtaining Prefix from ID $PrefixId"
|
|
|
|
|
|
$CurrentPrefix = Get-NetboxIPAMPrefix -Id $PrefixId -ErrorAction Stop
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2021-03-25 16:52:08 -04:00
|
|
|
|
if ($Force -or $PSCmdlet.ShouldProcess($CurrentPrefix.Prefix, 'Set')) {
|
|
|
|
|
|
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2021-03-25 16:52:08 -04:00
|
|
|
|
$URI = BuildNewURI -Segments $URIComponents.Segments
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2021-03-25 16:52:08 -04:00
|
|
|
|
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method $Method
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|