NetboxPS/Functions/Tenancy/ContactRoles/New-NetboxContactRole.ps1

72 lines
1.8 KiB
PowerShell
Raw Normal View History

2023-02-24 15:14:04 -05:00

2023-02-15 15:42:37 -05:00
function New-NetboxContactRole {
<#
.SYNOPSIS
Create a new contact role in Netbox
2023-02-24 15:14:04 -05:00
2023-02-15 15:42:37 -05:00
.DESCRIPTION
Creates a new contact role object in Netbox
2023-02-24 15:14:04 -05:00
2023-02-15 15:42:37 -05:00
.PARAMETER Name
The contact role name, e.g "Network Support"
2023-02-24 15:14:04 -05:00
2023-02-15 15:42:37 -05:00
.PARAMETER Slug
The unique URL for the role. Can only contain hypens, A-Z, a-z, 0-9, and underscores
2023-02-24 15:14:04 -05:00
2023-02-15 15:42:37 -05:00
.PARAMETER Description
Short description of the contact role
2023-02-24 15:14:04 -05:00
2023-02-15 15:42:37 -05:00
.PARAMETER Custom_Fields
A description of the Custom_Fields parameter.
2023-02-24 15:14:04 -05:00
2023-02-15 15:42:37 -05:00
.PARAMETER Raw
Return the unparsed data from the HTTP request
2023-02-24 15:14:04 -05:00
2023-02-15 15:42:37 -05:00
.EXAMPLE
PS C:\> New-NetboxContact -Name 'Leroy Jenkins' -Email 'leroy.jenkins@example.com'
2023-02-24 15:14:04 -05:00
2023-02-15 15:42:37 -05:00
.NOTES
Additional information about the function.
#>
2023-02-24 15:14:04 -05:00
2023-02-15 15:42:37 -05:00
[CmdletBinding(ConfirmImpact = 'Low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[ValidateLength(1, 100)]
[string]$Name,
2023-02-24 15:14:04 -05:00
2023-02-15 15:42:37 -05:00
[Parameter(Mandatory = $true)]
[ValidateLength(1, 100)]
[ValidatePattern('^[-a-zA-Z0-9_]+$')]
[string]$Slug,
2023-02-24 15:14:04 -05:00
2023-02-15 15:42:37 -05:00
[ValidateLength(0, 200)]
[string]$Description,
2023-02-24 15:14:04 -05:00
2023-02-15 15:42:37 -05:00
[hashtable]$Custom_Fields,
2023-02-24 15:14:04 -05:00
2023-02-15 15:42:37 -05:00
[switch]$Raw
)
2023-02-24 15:14:04 -05:00
2023-02-15 15:42:37 -05:00
process {
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contacts'))
$Method = 'POST'
2023-02-24 15:14:04 -05:00
2023-02-15 15:42:37 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
2023-02-24 15:14:04 -05:00
2023-02-15 15:42:37 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments
2023-02-24 15:14:04 -05:00
2023-02-15 15:42:37 -05:00
if ($PSCmdlet.ShouldProcess($Address, 'Create new contact')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
}
}
}