NetboxPS/Functions/Tenancy/Contacts/Set-NetboxContact.ps1

121 lines
2.7 KiB
PowerShell
Raw Normal View History

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

2023-02-24 10:23:10 -05:00
function Set-NetboxContact {
<#
.SYNOPSIS
Update a contact in Netbox
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
.DESCRIPTION
Updates a contact object in Netbox which can be linked to other objects
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
.PARAMETER Id
A description of the Id parameter.
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
.PARAMETER Name
The contacts full name, e.g "Leroy Jenkins"
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
.PARAMETER Email
Email address of the contact
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
.PARAMETER Group
Database ID of assigned group
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
.PARAMETER Title
Job title or other title related to the contact
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
.PARAMETER Phone
Telephone number
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
.PARAMETER Address
Physical address, usually mailing address
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
.PARAMETER Description
Short description of the contact
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
.PARAMETER Comments
Detailed comments. Markdown supported.
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
.PARAMETER Link
URI related to the contact
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
.PARAMETER Custom_Fields
A description of the Custom_Fields parameter.
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
.PARAMETER Force
A description of the Force parameter.
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
.PARAMETER Raw
A description of the Raw parameter.
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
.EXAMPLE
PS C:\> Set-NetboxContact -Id 10 -Name 'Leroy Jenkins' -Email 'leroy.jenkins@example.com'
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
.NOTES
Additional information about the function.
#>
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
[CmdletBinding(ConfirmImpact = 'Low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
2023-07-28 16:17:23 -04:00
[uint64[]]$Id,
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
[ValidateLength(1, 100)]
[string]$Name,
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
[ValidateLength(0, 254)]
[string]$Email,
2023-02-24 15:14:04 -05:00
2023-07-28 16:17:23 -04:00
[uint64]$Group,
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
[ValidateLength(0, 100)]
[string]$Title,
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
[ValidateLength(0, 50)]
[string]$Phone,
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
[ValidateLength(0, 200)]
[string]$Address,
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
[ValidateLength(0, 200)]
[string]$Description,
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
[string]$Comments,
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
[ValidateLength(0, 200)]
[string]$Link,
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
[hashtable]$Custom_Fields,
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
[switch]$Force,
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
[switch]$Raw
)
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
begin {
$Method = 'PATCH'
}
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
process {
foreach ($ContactId in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contacts', $ContactId))
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments
2023-02-24 15:14:04 -05:00
$CurrentContact = Get-NetboxContact -Id $ContactId -ErrorAction Stop
2023-02-24 15:14:04 -05:00
2023-02-24 10:23:10 -05:00
if ($Force -or $PSCmdlet.ShouldProcess($CurrentContact.Name, 'Update contact')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
}
}
}
}