NetboxPS/Functions/Tenancy/ContactAssignment/New-NetboxContactAssignment.ps1

79 lines
2.3 KiB
PowerShell

function New-NetboxContactAssignment {
<#
.SYNOPSIS
Create a new contact role assignment in Netbox
.DESCRIPTION
Creates a new contact role assignment in Netbox
.PARAMETER Content_Type
The content type for this assignment.
.PARAMETER Object_Id
ID of the object to assign.
.PARAMETER Contact
ID of the contact to assign.
.PARAMETER Role
ID of the contact role to assign.
.PARAMETER Priority
Piority of the contact assignment.
.PARAMETER Raw
Return the unparsed data from the HTTP request
.EXAMPLE
PS C:\> New-NetboxContactAssignment -Content_Type 'dcim.location' -Object_id 10 -Contact 15 -Role 10 -Priority 'Primary'
.NOTES
Valid content types: https://docs.netbox.dev/en/stable/features/contacts/#contacts_1
#>
[CmdletBinding(ConfirmImpact = 'Low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[ValidateSet('circuits.circuit', 'circuits.provider', 'circuits.provideraccount', 'dcim.device', 'dcim.location', 'dcim.manufacturer', 'dcim.powerpanel', 'dcim.rack', 'dcim.region', 'dcim.site', 'dcim.sitegroup', 'tenancy.tenant', 'virtualization.cluster', 'virtualization.clustergroup', 'virtualization.virtualmachine', IgnoreCase = $true)]
[string]$Content_Type,
[Parameter(Mandatory = $true)]
[uint64]$Object_Id,
[Parameter(Mandatory = $true)]
[uint64]$Contact,
[Parameter(Mandatory = $true)]
[uint64]$Role,
[ValidateSet('primary', 'secondary', 'tertiary', 'inactive', IgnoreCase = $true)]
[string]$Priority,
[switch]$Raw
)
begin {
$Method = 'POST'
}
process {
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contact-assignments'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($Content_Type, 'Create new contact assignment')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
}
}
}