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

80 lines
2.3 KiB
PowerShell
Raw Normal View History


function New-NetboxContactAssignment {
2023-02-16 09:47:00 -05:00
<#
.SYNOPSIS
Create a new contact role assignment in Netbox
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
.DESCRIPTION
Creates a new contact role assignment in Netbox
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
.PARAMETER Content_Type
The content type for this assignment.
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
.PARAMETER Object_Id
ID of the object to assign.
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
.PARAMETER Contact
ID of the contact to assign.
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
.PARAMETER Role
ID of the contact role to assign.
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
.PARAMETER Priority
Piority of the contact assignment.
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
.PARAMETER Raw
Return the unparsed data from the HTTP request
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
.EXAMPLE
PS C:\> New-NetboxContactAssignment -Content_Type 'dcim.location' -Object_id 10 -Contact 15 -Role 10 -Priority 'Primary'
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
.NOTES
Valid content types: https://docs.netbox.dev/en/stable/features/contacts/#contacts_1
2023-02-16 09:47:00 -05:00
#>
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
[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,
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
[Parameter(Mandatory = $true)]
2023-07-28 16:17:23 -04:00
[uint64]$Object_Id,
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
[Parameter(Mandatory = $true)]
2023-07-28 16:17:23 -04:00
[uint64]$Contact,
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
[Parameter(Mandatory = $true)]
2023-07-28 16:17:23 -04:00
[uint64]$Role,
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
[ValidateSet('primary', 'secondary', 'tertiary', 'inactive', IgnoreCase = $true)]
[string]$Priority,
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
[switch]$Raw
)
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
begin {
$Method = 'POST'
2023-02-16 09:47:00 -05:00
}
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
process {
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contact-assignments'))
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments
2023-02-24 15:14:04 -05:00
if ($PSCmdlet.ShouldProcess($Content_Type, 'Create new contact assignment')) {
2023-02-16 09:47:00 -05:00
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
}
}
}