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: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,
|
|
|
|
|
|
|
2021-03-25 16:52:08 -04:00
|
|
|
|
[string]$Status,
|
2020-03-23 12:18:01 -04:00
|
|
|
|
|
|
|
|
|
|
[uint16]$Tenant,
|
|
|
|
|
|
|
|
|
|
|
|
[uint16]$VRF,
|
|
|
|
|
|
|
|
|
|
|
|
[object]$Role,
|
|
|
|
|
|
|
|
|
|
|
|
[uint16]$NAT_Inside,
|
|
|
|
|
|
|
|
|
|
|
|
[hashtable]$Custom_Fields,
|
|
|
|
|
|
|
2021-03-25 16:52:08 -04:00
|
|
|
|
[ValidateSet('dcim.interface', 'virtualization.vminterface', IgnoreCase = $true)]
|
|
|
|
|
|
[string]$Assigned_Object_Type,
|
|
|
|
|
|
|
|
|
|
|
|
[uint16]$Assigned_Object_Id,
|
2020-03-23 12:18:01 -04:00
|
|
|
|
|
|
|
|
|
|
[string]$Description,
|
|
|
|
|
|
|
|
|
|
|
|
[switch]$Force
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
begin {
|
2021-03-25 16:52:08 -04:00
|
|
|
|
# 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"
|
2020-03-23 12:18:01 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
process {
|
|
|
|
|
|
foreach ($IPId in $Id) {
|
2021-03-25 16:52:08 -04:00
|
|
|
|
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"
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses', $IPId))
|
|
|
|
|
|
|
2021-03-25 16:52:08 -04:00
|
|
|
|
Write-Verbose "Obtaining IP from ID $IPId"
|
2020-03-23 12:18:01 -04:00
|
|
|
|
$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
|
|
|
|
|
|
|
2021-03-25 16:52:08 -04:00
|
|
|
|
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method $Method
|
2020-03-23 12:18:01 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|