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

111 lines
2.4 KiB
PowerShell
Raw Normal View History

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

2020-03-23 12:18:01 -04:00
function New-NetboxIPAMAddress {
<#
2020-03-23 12:18:01 -04:00
.SYNOPSIS
Create a new IP address to Netbox
2020-03-23 12:18:01 -04:00
.DESCRIPTION
Create a new IP address to Netbox with a status of Active by default.
2020-03-23 12:18:01 -04:00
.PARAMETER Address
IP address in CIDR notation: 192.168.1.1/24
2020-03-23 12:18:01 -04:00
.PARAMETER Status
Status of the IP. Defaults to Active
2020-03-23 12:18:01 -04:00
.PARAMETER Tenant
Tenant ID
2020-03-23 12:18:01 -04:00
.PARAMETER VRF
VRF ID
2020-03-23 12:18:01 -04:00
.PARAMETER Role
Role such as anycast, loopback, etc... Defaults to nothing
2020-03-23 12:18:01 -04:00
.PARAMETER NAT_Inside
ID of IP for NAT
2020-03-23 12:18:01 -04:00
.PARAMETER Custom_Fields
Custom field hash table. Will be validated by the API service
2020-03-23 12:18:01 -04:00
.PARAMETER Interface
ID of interface to apply IP
2020-03-23 12:18:01 -04:00
.PARAMETER Description
Description of IP address
.PARAMETER Dns_name
DNS Name of IP address (example : netbox.example.com)
.PARAMETER Assigned_Object_Type
Assigned Object Type dcim.interface or virtualization.vminterface
.PARAMETER Assigned_Object_Id
Assigned Object ID
2020-03-23 12:18:01 -04:00
.PARAMETER Raw
Return raw results from API service
2020-03-23 12:18:01 -04:00
.EXAMPLE
New-NetboxIPAMAddress -Address 192.0.2.1/32
Add new IP Address 192.0.2.1/32 with status active
2020-03-23 12:18:01 -04:00
.NOTES
Additional information about the function.
#>
[CmdletBinding(ConfirmImpact = 'Low',
SupportsShouldProcess = $true)]
2020-03-23 12:18:01 -04:00
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
2020-03-23 12:18:01 -04:00
[string]$Address,
2020-03-23 12:18:01 -04:00
[object]$Status = 'Active',
2023-07-28 16:17:23 -04:00
[uint64]$Tenant,
2023-07-28 16:17:23 -04:00
[uint64]$VRF,
2020-03-23 12:18:01 -04:00
[object]$Role,
2023-07-28 16:17:23 -04:00
[uint64]$NAT_Inside,
2020-03-23 12:18:01 -04:00
[hashtable]$Custom_Fields,
2023-07-28 16:17:23 -04:00
[uint64]$Interface,
2020-03-23 12:18:01 -04:00
[string]$Description,
[string]$Dns_name,
[ValidateSet('dcim.interface', 'virtualization.vminterface', IgnoreCase = $true)]
[string]$Assigned_Object_Type,
2023-07-28 16:17:23 -04:00
[uint64]$Assigned_Object_Id,
2020-03-23 12:18:01 -04:00
[switch]$Raw
)
process {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses'))
$Method = 'POST'
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($Address, 'Create new IP address')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
}
}
}