mirror of
https://github.com/benclaussen/NetboxPS.git
synced 2025-12-13 18:02:29 +00:00
Add Set-NetboxContactRole and Assignment functions
This commit is contained in:
parent
e4eb42a7a3
commit
40c7aac059
2 changed files with 164 additions and 0 deletions
|
|
@ -0,0 +1,84 @@
|
|||
|
||||
|
||||
function Set-NetboxContactAssignment {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Update a contact role assignment in Netbox
|
||||
|
||||
.DESCRIPTION
|
||||
Updates a 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
|
||||
Priority of the contact assignment.
|
||||
|
||||
.PARAMETER Raw
|
||||
Return the unparsed data from the HTTP request
|
||||
|
||||
.EXAMPLE
|
||||
PS C:\> Set-NetboxContactAssignment -Id 11 -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)]
|
||||
[uint64[]]$Id,
|
||||
|
||||
[Parameter(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,
|
||||
|
||||
[uint64]$Object_Id,
|
||||
|
||||
[uint64]$Contact,
|
||||
|
||||
[uint64]$Role,
|
||||
|
||||
[ValidateSet('primary', 'secondary', 'tertiary', 'inactive', IgnoreCase = $true)]
|
||||
[string]$Priority,
|
||||
|
||||
[switch]$Raw
|
||||
)
|
||||
|
||||
begin {
|
||||
$Method = 'Patch'
|
||||
}
|
||||
|
||||
process {
|
||||
foreach ($ContactAssignmentId in $Id) {
|
||||
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contact-assignments', $ContactAssignmentId))
|
||||
|
||||
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
|
||||
|
||||
$URI = BuildNewURI -Segments $URIComponents.Segments
|
||||
|
||||
$CurrentContactAssignment = Get-NetboxContactAssignment -Id $ContactAssignmentId -ErrorAction Stop
|
||||
|
||||
if ($PSCmdlet.ShouldProcess($CurrentContactAssignment.Id, 'Update contact assignment')) {
|
||||
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
80
Functions/Tenancy/ContactRoles/Set-NetboxContactRole.ps1
Normal file
80
Functions/Tenancy/ContactRoles/Set-NetboxContactRole.ps1
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
|
||||
function Set-NetboxContactRole {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Update a contact role in Netbox
|
||||
|
||||
.DESCRIPTION
|
||||
Updates a contact role in Netbox
|
||||
|
||||
.PARAMETER Name
|
||||
The contact role name, e.g "Network Support"
|
||||
|
||||
.PARAMETER Slug
|
||||
The unique URL for the role. Can only contain hypens, A-Z, a-z, 0-9, and underscores
|
||||
|
||||
.PARAMETER Description
|
||||
Short description of the contact role
|
||||
|
||||
.PARAMETER Custom_Fields
|
||||
A description of the Custom_Fields parameter.
|
||||
|
||||
.PARAMETER Raw
|
||||
Return the unparsed data from the HTTP request
|
||||
|
||||
.EXAMPLE
|
||||
PS C:\> New-NetboxContact -Name 'Leroy Jenkins' -Email 'leroy.jenkins@example.com'
|
||||
|
||||
.NOTES
|
||||
Additional information about the function.
|
||||
#>
|
||||
|
||||
[CmdletBinding(ConfirmImpact = 'Low',
|
||||
SupportsShouldProcess = $true)]
|
||||
[OutputType([pscustomobject])]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true,
|
||||
ValueFromPipelineByPropertyName = $true)]
|
||||
[uint64[]]$Id,
|
||||
|
||||
[Parameter(ValueFromPipelineByPropertyName = $true)]
|
||||
[ValidateLength(1, 100)]
|
||||
[string]$Name,
|
||||
|
||||
[ValidateLength(1, 100)]
|
||||
[ValidatePattern('^[-a-zA-Z0-9_]+$')]
|
||||
[string]$Slug,
|
||||
|
||||
[ValidateLength(0, 200)]
|
||||
[string]$Description,
|
||||
|
||||
[hashtable]$Custom_Fields,
|
||||
|
||||
[switch]$Raw
|
||||
)
|
||||
|
||||
begin {
|
||||
$Method = 'PATCH'
|
||||
}
|
||||
|
||||
process {
|
||||
foreach ($ContactRoleId in $Id) {
|
||||
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contacts', $ContactRoleId))
|
||||
|
||||
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
|
||||
|
||||
$URI = BuildNewURI -Segments $URIComponents.Segments
|
||||
|
||||
$CurrentContactRole = Get-NetboxContactRole -Id $ContactRoleId -ErrorAction Stop
|
||||
|
||||
if ($Force -or $PSCmdlet.ShouldProcess($CurrentContactRole.Name, 'Update contact role')) {
|
||||
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Reference in a new issue