Compare commits

...

36 commits
v1.8.5 ... dev

Author SHA1 Message Date
Ben Claussen
7129e7d3c7 Update version to 1.8.5 2023-11-09 12:09:07 -05:00
Ben Claussen
bb43ac490c Update psproj 2023-11-09 12:08:30 -05:00
Ben Claussen
59a28faff5 Correct variable references in ShouldProcess 2023-11-09 12:04:05 -05:00
Ben Claussen
b441e02e2b Update New-NetboxContactAssignment Content_Type parameter values and validation 2023-11-09 12:03:21 -05:00
Ben Claussen
40c7aac059 Add Set-NetboxContactRole and Assignment functions 2023-11-09 12:01:50 -05:00
Ben Claussen
e4eb42a7a3 Update psproj 2023-11-09 11:21:44 -05:00
Ben Claussen
bf01b354bd Move Get-NetboxTag file 2023-11-09 11:20:31 -05:00
Ben Claussen
cceb8fe765 Update Get-NetboxAPIDefinition for new path
- Add $Format parameter for json or yaml
2023-11-09 11:07:43 -05:00
Ben Claussen
8326e3eb29 Update New-NetboxContactAssignment name 2023-11-09 11:06:35 -05:00
Ben Claussen
26cc2b3c0d Merge branch 'master' into dev 2023-11-07 10:33:24 -05:00
Ben Claussen
88647882cc Update version to 1.8.4 2023-11-07 10:20:23 -05:00
Ben Claussen
2233de974d Remove incorrect parameter 2023-11-07 10:19:03 -05:00
Ben Claussen
9e00636fbe Add Set-NetboxIPAMAddressRange 2023-11-07 10:16:45 -05:00
Ben Claussen
bb0dfc0aa4 Update version to 1.8.3 2023-11-07 09:59:39 -05:00
Ben Claussen
4897d6b71f Remove whitespaces 2023-11-07 09:57:42 -05:00
Ben Claussen
6c2d358171 Update psproj with IPAMAddressRange files 2023-11-07 09:38:42 -05:00
Ben Claussen
383ca2b002 Move limit/offset parameters to end of list 2023-11-07 09:38:19 -05:00
Ben Claussen
985f920900 Add IPAMAddressRange functions 2023-11-07 09:37:47 -05:00
Ben Claussen
a63478a8d6 [uint64] updates 2023-11-07 09:37:01 -05:00
Ben Claussen
080d655f8d More uint64 updates for #49 2023-07-28 16:17:23 -04:00
Ben Claussen
914b245f24 dev v1.8.1 2023-07-28 15:59:13 -04:00
Ben Claussen
58fbbeb0cd Update uint16 to uint64 where applicable for #49 2023-07-28 15:38:16 -04:00
Ben Claussen
46068dcc04 Update psproj 2023-07-28 15:12:48 -04:00
Ben Claussen
5b0c2897e0 Merge branch 'master' into dev 2023-07-28 15:04:06 -04:00
Ben Claussen
c2a3dc285b Update version 1.8.0 2023-03-17 16:00:24 -04:00
Ben Claussen
bea65f0b06 Update vscode settings 2023-03-17 15:49:01 -04:00
Ben Claussen
cf1bcb3691 Update Postman for Netbox v3.4.5 2023-03-17 15:42:59 -04:00
Ben Claussen
0049ba4985 Fix braces 2023-03-17 15:37:09 -04:00
Ben Claussen
7c03023bb8 Update psproj 2023-03-17 15:35:27 -04:00
Ben Claussen
0fd989c82a Merge branch 'dev' of https://github.com/benclaussen/NetboxPS into dev 2023-03-17 15:29:29 -04:00
James Beck
d441a1ddac
Device port support (#44)
* Fixing #41

* Correct for OTBS

* Start work on Front and Rear ports

* Revert "Start work on Front and Rear ports"

This reverts commit 257709fe2af5af5fbe4496b2d5b68481d80bf101.

* Fixing #41

* Add-NetboxDCIMRearPort function

* Revert "Revert "Start work on Front and Rear ports""

This reverts commit 4f6625af2d.

* Fix incorrect parameter variable types

* Parameter type adjustments

* Create function to get tag information

* Added Mark_Connected parameter

* Add Set-NetboxDCIMRearPort function

* Added Remove-NetboxDCIMRearPort function

* Added validate pattern for Color parameter

* Added Add-NetboxDCIMFrontPort function

* Fixed param list missing Force parameter

* Added Set-NetboxDCIMFrontPort function

* Added Remove-NetboxDCIMFrontPort function

* Init. functions for cables and cable terminations

* Reformatting using OTBS
Also working on defining tags by slug as an extra parameter, which appears
only in Add-NetboxDCIMRearPort currently

* Remove Tags_Slug parameter
In hindsight implementing would create extra work that could be hard to
maintain. Can be easily achieved outside of the function.
2023-03-17 15:27:55 -04:00
Ben Claussen
7caf1a1d93 Merge branch 'master' of https://github.com/benclaussen/NetboxPS into dev 2023-03-13 09:57:58 -04:00
Ben Claussen
eb4d0eeb3b Fix location of whitespace cleanup in deploy.ps1 2023-03-13 09:49:31 -04:00
Ben Claussen
6f4309aa04 Increase version to 1.7.3 2023-03-13 09:42:30 -04:00
Ben Claussen
5421febdd1 Update deploy.ps1 to remove trailing whitespaces from psd1 2023-03-13 09:42:08 -04:00
SheffSix
a4c1886a23
Fixing Interface Type parameter (#42)
* Fixing #41
2023-03-13 09:26:25 -04:00
12 changed files with 426 additions and 126 deletions

View file

@ -1,13 +1,19 @@
 
function Get-NetboxAPIDefinition { function Get-NetboxAPIDefinition {
[CmdletBinding()] [CmdletBinding()]
param () param
(
[ValidateSet('json', 'yaml', IgnoreCase = $true)]
[string]$Format = 'json'
)
#$URI = "https://netbox.neonet.org/api/docs/?format=openapi" #$URI = "https://netbox.neonet.org/api/schema/?format=json"
$Segments = [System.Collections.ArrayList]::new(@('docs')) $Segments = [System.Collections.ArrayList]::new(@('schema'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary @{'format' = 'openapi' } $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary @{
'format' = $Format.ToLower()
}
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters -SkipConnectedCheck $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters -SkipConnectedCheck

View file

@ -1,35 +1,35 @@
 
function New-NetboxContactRole { function New-NetboxContactAssignment {
<# <#
.SYNOPSIS .SYNOPSIS
Create a new contact role in Netbox Create a new contact role assignment in Netbox
.DESCRIPTION .DESCRIPTION
Creates a new contact role object in Netbox Creates a new contact role assignment in Netbox
.PARAMETER Content_Type .PARAMETER Content_Type
A description of the Content_Type parameter. The content type for this assignment.
.PARAMETER Object_Id .PARAMETER Object_Id
A description of the Object_Id parameter. ID of the object to assign.
.PARAMETER Contact .PARAMETER Contact
A description of the Contact parameter. ID of the contact to assign.
.PARAMETER Role .PARAMETER Role
A description of the Role parameter. ID of the contact role to assign.
.PARAMETER Priority .PARAMETER Priority
A description of the Priority parameter. Piority of the contact assignment.
.PARAMETER Raw .PARAMETER Raw
Return the unparsed data from the HTTP request Return the unparsed data from the HTTP request
.EXAMPLE .EXAMPLE
PS C:\> New-NetboxContactAssignment -Name 'Leroy Jenkins' -Email 'leroy.jenkins@example.com' PS C:\> New-NetboxContactAssignment -Content_Type 'dcim.location' -Object_id 10 -Contact 15 -Role 10 -Priority 'Primary'
.NOTES .NOTES
Additional information about the function. Valid content types: https://docs.netbox.dev/en/stable/features/contacts/#contacts_1
#> #>
[CmdletBinding(ConfirmImpact = 'Low', [CmdletBinding(ConfirmImpact = 'Low',
@ -39,7 +39,8 @@ function New-NetboxContactRole {
( (
[Parameter(Mandatory = $true, [Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)] ValueFromPipelineByPropertyName = $true)]
[object]$Content_Type, [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,
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[uint64]$Object_Id, [uint64]$Object_Id,
@ -57,47 +58,17 @@ function New-NetboxContactRole {
) )
begin { begin {
# https://docs.netbox.dev/en/stable/features/contacts/ $Method = 'POST'
$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"
}
} }
process { process {
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contact-assignment')) $Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contact-assignments'))
$Method = 'POST'
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"
}
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($Address, 'Create new contact assignment')) { if ($PSCmdlet.ShouldProcess($Content_Type, 'Create new contact assignment')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
} }
} }

View file

@ -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
}
}
}
}

View file

@ -60,7 +60,7 @@ function New-NetboxContactRole {
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($Address, 'Create new contact')) { if ($PSCmdlet.ShouldProcess($Name, 'Create new contact')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
} }
} }

View 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
}
}
}
}

View file

@ -88,7 +88,7 @@ function New-NetboxContact {
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($Address, 'Create new contact')) { if ($PSCmdlet.ShouldProcess($Name, 'Create new contact')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
} }
} }

View file

@ -106,7 +106,7 @@ function Set-NetboxContact {
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
$CurrentContact = Get-NetboxContact -Id $ContactId $CurrentContact = Get-NetboxContact -Id $ContactId -ErrorAction Stop
if ($Force -or $PSCmdlet.ShouldProcess($CurrentContact.Name, 'Update contact')) { if ($Force -or $PSCmdlet.ShouldProcess($CurrentContact.Name, 'Update contact')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw

View file

@ -3,7 +3,7 @@
# #
# Generated by: Ben Claussen # Generated by: Ben Claussen
# #
# Generated on: 2023-11-07 # Generated on: 2023-11-09
# #
@{ @{
@ -12,7 +12,7 @@
RootModule = 'NetboxPS.psm1' RootModule = 'NetboxPS.psm1'
# Version number of this module. # Version number of this module.
ModuleVersion = '1.8.4' ModuleVersion = '1.8.5'
# Supported PSEditions # Supported PSEditions
# CompatiblePSEditions = @() # CompatiblePSEditions = @()
@ -101,15 +101,17 @@ FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface',
'Remove-NetboxDCIMInterfaceConnection', 'Remove-NetboxDCIMRearPort', 'Remove-NetboxDCIMInterfaceConnection', 'Remove-NetboxDCIMRearPort',
'Remove-NetboxDCIMSite', 'Remove-NetboxIPAMAddress', 'Remove-NetboxDCIMSite', 'Remove-NetboxIPAMAddress',
'Remove-NetboxIPAMAddressRange', 'Remove-NetboxVirtualMachine', 'Remove-NetboxIPAMAddressRange', 'Remove-NetboxVirtualMachine',
'Set-NetboxCipherSSL', 'Set-NetboxContact', 'Set-NetboxCredential', 'Set-NetboxCipherSSL', 'Set-NetboxContact',
'Set-NetboxDCIMDevice', 'Set-NetboxDCIMFrontPort', 'Set-NetboxContactAssignment', 'Set-NetboxContactRole',
'Set-NetboxDCIMInterface', 'Set-NetboxDCIMInterfaceConnection', 'Set-NetboxCredential', 'Set-NetboxDCIMDevice',
'Set-NetboxDCIMRearPort', 'Set-NetboxHostName', 'Set-NetboxHostPort', 'Set-NetboxDCIMFrontPort', 'Set-NetboxDCIMInterface',
'Set-NetboxHostScheme', 'Set-NetboxInvokeParams', 'Set-NetboxDCIMInterfaceConnection', 'Set-NetboxDCIMRearPort',
'Set-NetboxIPAMAddress', 'Set-NetboxIPAMAddressRange', 'Set-NetboxHostName', 'Set-NetboxHostPort', 'Set-NetboxHostScheme',
'Set-NetboxIPAMPrefix', 'Set-NetboxTimeout', 'Set-NetboxInvokeParams', 'Set-NetboxIPAMAddress',
'Set-NetboxUnstrustedSSL', 'Set-NetboxVirtualMachine', 'Set-NetboxIPAMAddressRange', 'Set-NetboxIPAMPrefix',
'Set-NetboxVirtualMachineInterface', 'Test-NetboxAPIConnected' 'Set-NetboxTimeout', 'Set-NetboxUnstrustedSSL',
'Set-NetboxVirtualMachine', 'Set-NetboxVirtualMachineInterface',
'Test-NetboxAPIConnected'
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = '*' CmdletsToExport = '*'

View file

@ -40,6 +40,7 @@
<Folder>Functions\DCIM\RearPorts</Folder> <Folder>Functions\DCIM\RearPorts</Folder>
<Folder>Functions\Extras</Folder> <Folder>Functions\Extras</Folder>
<Folder>Functions\IPAM\Range</Folder> <Folder>Functions\IPAM\Range</Folder>
<Folder>Functions\Extras\Tags</Folder>
</Folders> </Folders>
<Files> <Files>
<File Build="2">NetboxPS.psd1</File> <File Build="2">NetboxPS.psd1</File>
@ -134,7 +135,7 @@
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxContactAssignment_ps1" ExportFunctions="True">Functions\Tenancy\ContactAssignment\Get-NetboxContactAssignment.ps1</File> <File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxContactAssignment_ps1" ExportFunctions="True">Functions\Tenancy\ContactAssignment\Get-NetboxContactAssignment.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxContentType_ps1" ExportFunctions="False">Functions\Setup\Support\Get-NetboxContentType.ps1</File> <File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxContentType_ps1" ExportFunctions="False">Functions\Setup\Support\Get-NetboxContentType.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-New-NetboxContactAssignment_ps1" ExportFunctions="True">Functions\Tenancy\ContactAssignment\New-NetboxContactAssignment.ps1</File> <File Build="0" Shared="True" ReferenceFunction="Invoke-New-NetboxContactAssignment_ps1" ExportFunctions="True">Functions\Tenancy\ContactAssignment\New-NetboxContactAssignment.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Set-NetboxContact_ps1" ExportFunctions="False">Functions\Tenancy\Contacts\Set-NetboxContact.ps1</File> <File Build="0" Shared="True" ReferenceFunction="Invoke-Set-NetboxContact_ps1" ExportFunctions="True">Functions\Tenancy\Contacts\Set-NetboxContact.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Test-NetboxAPIConnected_ps1" ExportFunctions="False">Functions\Setup\Support\Test-NetboxAPIConnected.ps1</File> <File Build="0" Shared="True" ReferenceFunction="Invoke-Test-NetboxAPIConnected_ps1" ExportFunctions="False">Functions\Setup\Support\Test-NetboxAPIConnected.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxDCIMCableTermination_ps1" ExportFunctions="False">Functions\DCIM\Cable Terminations\Get-NetboxDCIMCableTermination.ps1</File> <File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxDCIMCableTermination_ps1" ExportFunctions="False">Functions\DCIM\Cable Terminations\Get-NetboxDCIMCableTermination.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxDCIMCable_ps1" ExportFunctions="False">Functions\DCIM\Cables\Get-NetboxDCIMCable.ps1</File> <File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxDCIMCable_ps1" ExportFunctions="False">Functions\DCIM\Cables\Get-NetboxDCIMCable.ps1</File>
@ -148,11 +149,14 @@
<File Build="0" Shared="True" ReferenceFunction="Invoke-Set-NetboxDCIMRearPort_ps1" ExportFunctions="False">Functions\DCIM\RearPorts\Set-NetboxDCIMRearPort.ps1</File> <File Build="0" Shared="True" ReferenceFunction="Invoke-Set-NetboxDCIMRearPort_ps1" ExportFunctions="False">Functions\DCIM\RearPorts\Set-NetboxDCIMRearPort.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-New-NetboxDCIMSite_ps1" ExportFunctions="False">Functions\DCIM\Sites\New-NetboxDCIMSite.ps1</File> <File Build="0" Shared="True" ReferenceFunction="Invoke-New-NetboxDCIMSite_ps1" ExportFunctions="False">Functions\DCIM\Sites\New-NetboxDCIMSite.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Remove-NetboxDCIMSite_ps1" ExportFunctions="False">Functions\DCIM\Sites\Remove-NetboxDCIMSite.ps1</File> <File Build="0" Shared="True" ReferenceFunction="Invoke-Remove-NetboxDCIMSite_ps1" ExportFunctions="False">Functions\DCIM\Sites\Remove-NetboxDCIMSite.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxTag_ps1" ExportFunctions="False">Functions\Extras\Get-NetboxTag.ps1</File> <File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxTag_ps1" ExportFunctions="True">Functions\Extras\Tags\Get-NetboxTag.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Clear-NetboxCredential_ps1" ExportFunctions="False">Functions\Setup\Clear-NetboxCredential.ps1</File> <File Build="0" Shared="True" ReferenceFunction="Invoke-Clear-NetboxCredential_ps1" ExportFunctions="False">Functions\Setup\Clear-NetboxCredential.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxIPAMAddressRange_ps1" ExportFunctions="True">Functions\IPAM\Range\Get-NetboxIPAMAddressRange.ps1</File> <File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxIPAMAddressRange_ps1" ExportFunctions="True">Functions\IPAM\Range\Get-NetboxIPAMAddressRange.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-New-NetboxIPAMAddressRange_ps1" ExportFunctions="True">Functions\IPAM\Range\New-NetboxIPAMAddressRange.ps1</File> <File Build="0" Shared="True" ReferenceFunction="Invoke-New-NetboxIPAMAddressRange_ps1" ExportFunctions="True">Functions\IPAM\Range\New-NetboxIPAMAddressRange.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Remove-NetboxIPAMAddressRange_ps1" ExportFunctions="True">Functions\IPAM\Range\Remove-NetboxIPAMAddressRange.ps1</File> <File Build="0" Shared="True" ReferenceFunction="Invoke-Remove-NetboxIPAMAddressRange_ps1" ExportFunctions="True">Functions\IPAM\Range\Remove-NetboxIPAMAddressRange.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Set-NetboxIPAMAddressRange_ps1" ExportFunctions="True">Functions\IPAM\Range\Set-NetboxIPAMAddressRange.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Set-NetboxContactRole_ps1" ExportFunctions="True">Functions\Tenancy\ContactRoles\Set-NetboxContactRole.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Set-NetboxContactAssignment_ps1" ExportFunctions="True">Functions\Tenancy\ContactAssignment\Set-NetboxContactAssignment.ps1</File>
</Files> </Files>
<StartupScript>R:\Netbox\NetboxPS\Test-Module.ps1</StartupScript> <StartupScript>R:\Netbox\NetboxPS\Test-Module.ps1</StartupScript>
</Project> </Project>

View file

@ -3,7 +3,7 @@
# #
# Generated by: Ben Claussen # Generated by: Ben Claussen
# #
# Generated on: 2023-11-07 # Generated on: 2023-11-09
# #
@{ @{
@ -12,7 +12,7 @@
RootModule = 'NetboxPS.psm1' RootModule = 'NetboxPS.psm1'
# Version number of this module. # Version number of this module.
ModuleVersion = '1.8.4' ModuleVersion = '1.8.5'
# Supported PSEditions # Supported PSEditions
# CompatiblePSEditions = @() # CompatiblePSEditions = @()
@ -101,15 +101,17 @@ FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface',
'Remove-NetboxDCIMInterfaceConnection', 'Remove-NetboxDCIMRearPort', 'Remove-NetboxDCIMInterfaceConnection', 'Remove-NetboxDCIMRearPort',
'Remove-NetboxDCIMSite', 'Remove-NetboxIPAMAddress', 'Remove-NetboxDCIMSite', 'Remove-NetboxIPAMAddress',
'Remove-NetboxIPAMAddressRange', 'Remove-NetboxVirtualMachine', 'Remove-NetboxIPAMAddressRange', 'Remove-NetboxVirtualMachine',
'Set-NetboxCipherSSL', 'Set-NetboxContact', 'Set-NetboxCredential', 'Set-NetboxCipherSSL', 'Set-NetboxContact',
'Set-NetboxDCIMDevice', 'Set-NetboxDCIMFrontPort', 'Set-NetboxContactAssignment', 'Set-NetboxContactRole',
'Set-NetboxDCIMInterface', 'Set-NetboxDCIMInterfaceConnection', 'Set-NetboxCredential', 'Set-NetboxDCIMDevice',
'Set-NetboxDCIMRearPort', 'Set-NetboxHostName', 'Set-NetboxHostPort', 'Set-NetboxDCIMFrontPort', 'Set-NetboxDCIMInterface',
'Set-NetboxHostScheme', 'Set-NetboxInvokeParams', 'Set-NetboxDCIMInterfaceConnection', 'Set-NetboxDCIMRearPort',
'Set-NetboxIPAMAddress', 'Set-NetboxIPAMAddressRange', 'Set-NetboxHostName', 'Set-NetboxHostPort', 'Set-NetboxHostScheme',
'Set-NetboxIPAMPrefix', 'Set-NetboxTimeout', 'Set-NetboxInvokeParams', 'Set-NetboxIPAMAddress',
'Set-NetboxUnstrustedSSL', 'Set-NetboxVirtualMachine', 'Set-NetboxIPAMAddressRange', 'Set-NetboxIPAMPrefix',
'Set-NetboxVirtualMachineInterface', 'Test-NetboxAPIConnected' 'Set-NetboxTimeout', 'Set-NetboxUnstrustedSSL',
'Set-NetboxVirtualMachine', 'Set-NetboxVirtualMachineInterface',
'Test-NetboxAPIConnected'
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = '*' CmdletsToExport = '*'

View file

@ -715,13 +715,19 @@ function Get-ModelDefinition {
function Get-NetboxAPIDefinition { function Get-NetboxAPIDefinition {
[CmdletBinding()] [CmdletBinding()]
param () param
(
[ValidateSet('json', 'yaml', IgnoreCase = $true)]
[string]$Format = 'json'
)
#$URI = "https://netbox.neonet.org/api/docs/?format=openapi" #$URI = "https://netbox.neonet.org/api/schema/?format=json"
$Segments = [System.Collections.ArrayList]::new(@('docs')) $Segments = [System.Collections.ArrayList]::new(@('schema'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary @{'format' = 'openapi' } $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary @{
'format' = $Format.ToLower()
}
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters -SkipConnectedCheck $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters -SkipConnectedCheck
@ -3708,7 +3714,7 @@ function New-NetboxContact {
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($Address, 'Create new contact')) { if ($PSCmdlet.ShouldProcess($Name, 'Create new contact')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
} }
} }
@ -3723,37 +3729,37 @@ function New-NetboxContact {
#region File New-NetboxContactAssignment.ps1 #region File New-NetboxContactAssignment.ps1
function New-NetboxContactRole { function New-NetboxContactAssignment {
<# <#
.SYNOPSIS .SYNOPSIS
Create a new contact role in Netbox Create a new contact role assignment in Netbox
.DESCRIPTION .DESCRIPTION
Creates a new contact role object in Netbox Creates a new contact role assignment in Netbox
.PARAMETER Content_Type .PARAMETER Content_Type
A description of the Content_Type parameter. The content type for this assignment.
.PARAMETER Object_Id .PARAMETER Object_Id
A description of the Object_Id parameter. ID of the object to assign.
.PARAMETER Contact .PARAMETER Contact
A description of the Contact parameter. ID of the contact to assign.
.PARAMETER Role .PARAMETER Role
A description of the Role parameter. ID of the contact role to assign.
.PARAMETER Priority .PARAMETER Priority
A description of the Priority parameter. Piority of the contact assignment.
.PARAMETER Raw .PARAMETER Raw
Return the unparsed data from the HTTP request Return the unparsed data from the HTTP request
.EXAMPLE .EXAMPLE
PS C:\> New-NetboxContactAssignment -Name 'Leroy Jenkins' -Email 'leroy.jenkins@example.com' PS C:\> New-NetboxContactAssignment -Content_Type 'dcim.location' -Object_id 10 -Contact 15 -Role 10 -Priority 'Primary'
.NOTES .NOTES
Additional information about the function. Valid content types: https://docs.netbox.dev/en/stable/features/contacts/#contacts_1
#> #>
[CmdletBinding(ConfirmImpact = 'Low', [CmdletBinding(ConfirmImpact = 'Low',
@ -3763,7 +3769,8 @@ function New-NetboxContactRole {
( (
[Parameter(Mandatory = $true, [Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)] ValueFromPipelineByPropertyName = $true)]
[object]$Content_Type, [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,
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[uint64]$Object_Id, [uint64]$Object_Id,
@ -3781,47 +3788,17 @@ function New-NetboxContactRole {
) )
begin { begin {
# https://docs.netbox.dev/en/stable/features/contacts/ $Method = 'POST'
$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"
}
} }
process { process {
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contact-assignment')) $Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contact-assignments'))
$Method = 'POST'
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"
}
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($Address, 'Create new contact assignment')) { if ($PSCmdlet.ShouldProcess($Content_Type, 'Create new contact assignment')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
} }
} }
@ -3897,7 +3874,7 @@ function New-NetboxContactRole {
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($Address, 'Create new contact')) { if ($PSCmdlet.ShouldProcess($Name, 'Create new contact')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
} }
} }
@ -5181,7 +5158,7 @@ function Set-NetboxContact {
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
$CurrentContact = Get-NetboxContact -Id $ContactId $CurrentContact = Get-NetboxContact -Id $ContactId -ErrorAction Stop
if ($Force -or $PSCmdlet.ShouldProcess($CurrentContact.Name, 'Update contact')) { if ($Force -or $PSCmdlet.ShouldProcess($CurrentContact.Name, 'Update contact')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
@ -5194,6 +5171,180 @@ function Set-NetboxContact {
#endregion
#region File Set-NetboxContactAssignment.ps1
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
}
}
}
}
#endregion
#region File Set-NetboxContactRole.ps1
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
}
}
}
}
#endregion #endregion
#region File Set-NetboxCredential.ps1 #region File Set-NetboxCredential.ps1