2021-03-30 16:34:25 +02:00
|
|
|
|
<#
|
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:52
|
|
|
|
|
|
Created by: Claussen
|
|
|
|
|
|
Organization: NEOnet
|
|
|
|
|
|
Filename: Remove-NetboxIPAMAddress.ps1
|
|
|
|
|
|
===========================================================================
|
|
|
|
|
|
.DESCRIPTION
|
|
|
|
|
|
A description of the file.
|
|
|
|
|
|
#>
|
|
|
|
|
|
|
|
|
|
|
|
function Remove-NetboxIPAMAddress {
|
2021-03-30 16:34:25 +02:00
|
|
|
|
<#
|
2020-03-23 12:18:01 -04:00
|
|
|
|
.SYNOPSIS
|
|
|
|
|
|
Remove an IP address from Netbox
|
2021-03-30 16:34:25 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
.DESCRIPTION
|
|
|
|
|
|
Removes/deletes an IP address from Netbox by ID and optional other filters
|
2021-03-30 16:34:25 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
.PARAMETER Id
|
|
|
|
|
|
Database ID of the IP address object.
|
2021-03-30 16:34:25 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
.PARAMETER Force
|
|
|
|
|
|
Do not confirm.
|
2021-03-30 16:34:25 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
.EXAMPLE
|
|
|
|
|
|
PS C:\> Remove-NetboxIPAMAddress -Id $value1
|
2021-03-30 16:34:25 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
.NOTES
|
|
|
|
|
|
Additional information about the function.
|
|
|
|
|
|
#>
|
2021-03-30 16:34:25 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
[CmdletBinding(ConfirmImpact = 'High',
|
2021-03-30 16:34:25 +02:00
|
|
|
|
SupportsShouldProcess = $true)]
|
2020-03-23 12:18:01 -04:00
|
|
|
|
param
|
|
|
|
|
|
(
|
|
|
|
|
|
[Parameter(Mandatory = $true,
|
2021-03-30 16:34:25 +02:00
|
|
|
|
ValueFromPipelineByPropertyName = $true)]
|
|
|
|
|
|
[int[]]$Id,
|
|
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
[switch]$Force
|
|
|
|
|
|
)
|
2021-03-30 16:34:25 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
process {
|
|
|
|
|
|
foreach ($IPId in $Id) {
|
|
|
|
|
|
$CurrentIP = Get-NetboxIPAMAddress -Id $IPId -ErrorAction Stop
|
2021-03-30 16:34:25 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses', $IPId))
|
2021-03-30 16:34:25 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
if ($Force -or $pscmdlet.ShouldProcess($CurrentIP.Address, "Delete")) {
|
|
|
|
|
|
$URI = BuildNewURI -Segments $Segments
|
2021-03-30 16:34:25 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
InvokeNetboxRequest -URI $URI -Method DELETE
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|