NetboxPS/Functions/IPAM/Prefix/Set-NetboxIPAMPrefix.ps1
Alexis La Goutte 8167b0dbf0
Fix PSSA Warning (#20)
* Fix trailing white space

using Invoke-ScriptAnalyzer -Fix -Path . -Recurse

* add settings.json for configure Visual Code (Formatter)

* PSSA: Fix Command accepts pipeline input but has not defined a process block

* PSSA: Fix PSUseDeclaredVarsMoreThanAssignments

The variable 'I_B' is assigned but never used
The variable 'I_A' is assigned but never used

* PSSA: Fix PSUseShouldProcessForStateChangingFunctions

Function New-/Set-... has verb that could change system state. Therefore, the function has to support 'ShouldProcess'
2021-07-23 16:06:42 -04:00

92 lines
2.8 KiB
PowerShell

<#
.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
}
}
}
}