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

120 lines
3.2 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:51
Created by: Claussen
Organization: NEOnet
Filename: New-NetboxIPAMAddress.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function New-NetboxIPAMAddress {
<#
.SYNOPSIS
Create a new IP address to Netbox
.DESCRIPTION
Create a new IP address to Netbox with a status of Active by default.
.PARAMETER Address
IP address in CIDR notation: 192.168.1.1/24
.PARAMETER Status
Status of the IP. Defaults to Active
.PARAMETER Tenant
Tenant ID
.PARAMETER VRF
VRF ID
.PARAMETER Role
Role such as anycast, loopback, etc... Defaults to nothing
.PARAMETER NAT_Inside
ID of IP for NAT
.PARAMETER Custom_Fields
Custom field hash table. Will be validated by the API service
.PARAMETER Interface
ID of interface to apply IP
.PARAMETER Description
Description of IP address
.PARAMETER Force
Do not prompt for confirmation to create IP.
2020-03-23 12:18:01 -04:00
.PARAMETER Raw
Return raw results from API service
.EXAMPLE
PS C:\> Create-NetboxIPAMAddress
.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,
[object]$Status = 'Active',
[uint16]$Tenant,
[uint16]$VRF,
[object]$Role,
[uint16]$NAT_Inside,
[hashtable]$Custom_Fields,
[uint16]$Interface,
[string]$Description,
[switch]$Force,
2020-03-23 12:18:01 -04:00
[switch]$Raw
)
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses'))
$Method = 'POST'
# # 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
# }
# }
#
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
2020-03-23 12:18:01 -04:00
$URI = BuildNewURI -Segments $URIComponents.Segments
if ($Force -or $PSCmdlet.ShouldProcess($Address, 'Create new IP address')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
}
}