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

59 lines
1.5 KiB
PowerShell
Raw Normal View History

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