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

100 lines
2.3 KiB
PowerShell
Raw Normal View History

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

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