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

109 lines
3 KiB
PowerShell
Raw Normal View History

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

2023-02-16 09:47:00 -05:00
function New-NetboxContactRole {
<#
.SYNOPSIS
Create a new contact role in Netbox
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
.DESCRIPTION
Creates a new contact role object in Netbox
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
.PARAMETER Content_Type
A description of the Content_Type parameter.
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
.PARAMETER Object_Id
A description of the Object_Id parameter.
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
.PARAMETER Contact
A description of the Contact parameter.
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
.PARAMETER Role
A description of the Role parameter.
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
.PARAMETER Priority
A description of the Priority parameter.
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 -Name 'Leroy Jenkins' -Email 'leroy.jenkins@example.com'
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
.NOTES
Additional information about the function.
#>
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)]
[object]$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 {
# https://docs.netbox.dev/en/stable/features/contacts/
$AllowedContentTypes = @{
10 = "circuits.circuit"
7 = "circuits.provider"
19 = "dcim.device"
25 = "dcim.location"
29 = "dcim.manufacturer"
77 = "dcim.powerpanel"
20 = "dcim.rack"
30 = "dcim.region"
18 = "dcim.site"
92 = "dcim.sitegroup"
58 = "tenancy.tenant"
63 = "virtualization.cluster"
64 = "virtualization.clustergroup"
61 = "virtualization.virtualmachine"
}
}
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
process {
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contact-assignment'))
$Method = 'POST'
2023-02-24 15:14:04 -05:00
2023-02-16 09:47:00 -05:00
if ($Content_Type -is [string]) {
# Need to convert this to an integer
$Content_Type = ($AllowedContentTypes.GetEnumerator() | Where-Object {
$_.Value -eq $Content_Type
}).Key
} elseif ($Content_Type -is [int]) {
if ($Content_Type -notin $($AllowedContentTypes).Keys) {
throw "Invalid content type defined"
}
} else {
throw "Invalid content type defined"
}
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
2023-02-16 09:47:00 -05:00
if ($PSCmdlet.ShouldProcess($Address, 'Create new contact assignment')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
}
}
}