NetboxPS/Functions/IPAM/Address/Remove-NetboxIPAMAddress.ps1

47 lines
1.1 KiB
PowerShell
Raw Normal View History

2022-12-06 13:34:52 -05:00

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