From ad4c80e4f6c570a7856f48fb46e06665c5495698 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Tue, 23 Mar 2021 14:39:08 -0400 Subject: [PATCH] Add Set-NetboxIPAMPrefix function --- .../IPAM/Prefix/Set-NetboxIPAMPrefix.ps1 | 92 +++++++++++++++++++ NetboxPS.psproj | 1 + 2 files changed, 93 insertions(+) create mode 100644 Functions/IPAM/Prefix/Set-NetboxIPAMPrefix.ps1 diff --git a/Functions/IPAM/Prefix/Set-NetboxIPAMPrefix.ps1 b/Functions/IPAM/Prefix/Set-NetboxIPAMPrefix.ps1 new file mode 100644 index 0000000..0670ad7 --- /dev/null +++ b/Functions/IPAM/Prefix/Set-NetboxIPAMPrefix.ps1 @@ -0,0 +1,92 @@ +<# + .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, + + [string]$Prefix, + + [string]$Status, + + [uint16]$Tenant, + + [uint16]$Site, + + [uint16]$VRF, + + [uint16]$VLAN, + + [object]$Role, + + [hashtable]$Custom_Fields, + + [string]$Description, + + [switch]$Is_Pool, + + [switch]$Force + ) + + begin { + # Write-Verbose "Validating enum properties" + # $Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses', 0)) + $Method = 'PATCH' + # + # # Value validation + # $ModelDefinition = GetModelDefinitionFromURIPath -Segments $Segments -Method $Method + # $EnumProperties = GetModelEnumProperties -ModelDefinition $ModelDefinition + # + # 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]" + # } + # } + # + # Write-Verbose "Finished enum validation" + } + + process { + foreach ($PrefixId in $Id) { + $Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes', $PrefixId)) + + Write-Verbose "Obtaining Prefix from ID $PrefixId" + $CurrentPrefix = Get-NetboxIPAMPrefix -Id $PrefixId -ErrorAction Stop + + if ($Force -or $PSCmdlet.ShouldProcess($CurrentPrefix.Prefix, 'Set')) { + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force' + + $URI = BuildNewURI -Segments $URIComponents.Segments + + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method $Method + } + } + } +} + + + + + + + + diff --git a/NetboxPS.psproj b/NetboxPS.psproj index c1ba101..b1f5a6f 100644 --- a/NetboxPS.psproj +++ b/NetboxPS.psproj @@ -103,6 +103,7 @@ Functions\Circuits\Providers\Get-NetboxCircuitProvider.ps1 Functions\Circuits\Types\Get-NetboxCircuitType.ps1 Functions\Helpers\Get-ModelDefinition.ps1 + Functions\IPAM\Prefix\Set-NetboxIPAMPrefix.ps1 R:\Netbox\NetboxPS\Test-Module.ps1 \ No newline at end of file