NetboxPS/Functions/IPAM/Address/Set-NetboxIPAMAddress.ps1
Ben Claussen cfb53cf933
Version 1.3.0 (#3)
* Add `OPTIONS` method validation

* Remove parameter validation as workaround for CHOICES API endpoint until further testing

* Add help block for Get-NetboxTenant

* SkipConnectedCheck for Get-NetboxAPIDefinition

* Correct help block for New-NetboxIPAMAddress

* Add parameter position 0 for 'Address' in Get-NetboxIPAMAddress

* Allow pipeline input for Address parameter in New-NetboxIPAMAddress

* Update parameter types

* Add parameter sets and logic for ID/Query searches

* Add Get-NetboxDCIMSite

* Update psproj

* Update deploy.ps1

* Move Get-NetboxCircuit

* Add Circuit cmdlets
- New-NetboxCircuit
- Get-NetboxCircuitProvider
- Get-NetboxCircuitTermination
- Get-NetboxCircuitType

* Update deploy script output path

* Update Set-NetboxIPAMAddress
- Replace Interface parameter with Assigned_Object_Type and Assigned_Object_Id
- Add validation logic for Assigned_Object_ parameters
- Change Status parameter to string

* Add Get-ModelDefinition function

* Update psproj

* Update deploy.ps1 variables

* Update exported files

* Remove references to `_choices` API calls

* Add Postman collection

* Add Postman collection

* Update deploy.ps1

* Add Set-NetboxIPAMPrefix function

* Increment version to 1.3.0

Co-authored-by: Ben Claussen <claussen@neonet.org>
2021-03-25 16:52:08 -04:00

93 lines
No EOL
3.6 KiB
PowerShell

<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 11:53
Created by: Claussen
Organization: NEOnet
Filename: Set-NetboxIPAMAddress.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Set-NetboxIPAMAddress {
[CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
[string]$Address,
[string]$Status,
[uint16]$Tenant,
[uint16]$VRF,
[object]$Role,
[uint16]$NAT_Inside,
[hashtable]$Custom_Fields,
[ValidateSet('dcim.interface', 'virtualization.vminterface', IgnoreCase = $true)]
[string]$Assigned_Object_Type,
[uint16]$Assigned_Object_Id,
[string]$Description,
[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 ($IPId in $Id) {
if ($PSBoundParameters.ContainsKey('Assigned_Object_Type') -or $PSBoundParameters.ContainsKey('Assigned_Object_Id')) {
if ((-not [string]::IsNullOrWhiteSpace($Assigned_Object_Id)) -and [string]::IsNullOrWhiteSpace($Assigned_Object_Type)) {
throw "Assigned_Object_Type is required when specifying Assigned_Object_Id"
} elseif ((-not [string]::IsNullOrWhiteSpace($Assigned_Object_Type)) -and [string]::IsNullOrWhiteSpace($Assigned_Object_Id)) {
throw "Assigned_Object_Id is required when specifying Assigned_Object_Type"
}
}
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses', $IPId))
Write-Verbose "Obtaining IP from ID $IPId"
$CurrentIP = Get-NetboxIPAMAddress -Id $IPId -ErrorAction Stop
if ($Force -or $PSCmdlet.ShouldProcess($CurrentIP.Address, 'Set')) {
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method $Method
}
}
}
}