From d85f67546937e80e01d02a08091760ae2bddff81 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Wed, 15 Feb 2023 15:39:36 -0500 Subject: [PATCH 01/14] Add Get-NetboxContact function --- .../Tenancy/Contacts/Get-NetboxContact.ps1 | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 Functions/Tenancy/Contacts/Get-NetboxContact.ps1 diff --git a/Functions/Tenancy/Contacts/Get-NetboxContact.ps1 b/Functions/Tenancy/Contacts/Get-NetboxContact.ps1 new file mode 100644 index 0000000..964b11f --- /dev/null +++ b/Functions/Tenancy/Contacts/Get-NetboxContact.ps1 @@ -0,0 +1,120 @@ + +function Get-NetboxContact { +<# + .SYNOPSIS + Get a contact from Netbox + + .DESCRIPTION + Obtain a contact or contacts from Netbox by ID or query + + .PARAMETER Name + The specific name of the Contact. Must match exactly as is defined in Netbox + + .PARAMETER Id + The database ID of the Contact + + .PARAMETER Query + A standard search query that will match one or more Contacts. + + .PARAMETER Email + Email address of the contact + + .PARAMETER Title + Title of the contact + + .PARAMETER Phone + Telephone number of the contact + + .PARAMETER Address + Physical address of the contact + + .PARAMETER Group + The specific group as defined in Netbox. + + .PARAMETER GroupID + The database ID of the group in Netbox + + .PARAMETER Limit + Limit the number of results to this number + + .PARAMETER Offset + Start the search at this index in results + + .PARAMETER Raw + Return the unparsed data from the HTTP request + + .EXAMPLE + PS C:\> Get-NetboxContact + + .NOTES + Additional information about the function. +#> + + [CmdletBinding(DefaultParameterSetName = 'Query')] + param + ( + [Parameter(ParameterSetName = 'Query', + Position = 0)] + [string]$Name, + + [Parameter(ParameterSetName = 'ByID')] + [uint32[]]$Id, + + [Parameter(ParameterSetName = 'Query')] + [string]$Query, + + [Parameter(ParameterSetName = 'Query')] + [string]$Email, + + [Parameter(ParameterSetName = 'Query')] + [string]$Title, + + [Parameter(ParameterSetName = 'Query')] + [string]$Phone, + + [Parameter(ParameterSetName = 'Query')] + [string]$Address, + + [Parameter(ParameterSetName = 'Query')] + [string]$Group, + + [Parameter(ParameterSetName = 'Query')] + [uint16]$GroupID, + + [Parameter(ParameterSetName = 'Query')] + [uint16]$Limit, + + [Parameter(ParameterSetName = 'Query')] + [uint16]$Offset, + + [switch]$Raw + ) + + switch ($PSCmdlet.ParameterSetName) { + 'ById' { + foreach ($Contact_ID in $Id) { + $Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contacts', $Contact_ID)) + + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id' + + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters + + InvokeNetboxRequest -URI $uri -Raw:$Raw + } + + break + } + + default { + $Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contacts')) + + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters + + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters + + InvokeNetboxRequest -URI $uri -Raw:$Raw + + break + } + } +} \ No newline at end of file From 6dd82ee688d297c59fae3be90dc155f14a1fec05 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Wed, 15 Feb 2023 15:40:59 -0500 Subject: [PATCH 02/14] Add Get-NetboxContactRole function --- .../ContactRoles/Get-NetboxContactRole.ps1 | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 Functions/Tenancy/ContactRoles/Get-NetboxContactRole.ps1 diff --git a/Functions/Tenancy/ContactRoles/Get-NetboxContactRole.ps1 b/Functions/Tenancy/ContactRoles/Get-NetboxContactRole.ps1 new file mode 100644 index 0000000..f619189 --- /dev/null +++ b/Functions/Tenancy/ContactRoles/Get-NetboxContactRole.ps1 @@ -0,0 +1,90 @@ + +function Get-NetboxContactRole { +<# + .SYNOPSIS + Get a contact role from Netbox + + .DESCRIPTION + A detailed description of the Get-NetboxContactRole function. + + .PARAMETER Name + The specific name of the contact role. Must match exactly as is defined in Netbox + + .PARAMETER Id + The database ID of the contact role + + .PARAMETER Query + A standard search query that will match one or more contact roles. + + .PARAMETER Limit + Limit the number of results to this number + + .PARAMETER Offset + Start the search at this index in results + + .PARAMETER Raw + Return the unparsed data from the HTTP request + + .EXAMPLE + PS C:\> Get-NetboxContactRole + + .NOTES + Additional information about the function. +#> + + [CmdletBinding(DefaultParameterSetName = 'Query')] + param + ( + [Parameter(ParameterSetName = 'Query', + Position = 0)] + [string]$Name, + + [Parameter(ParameterSetName = 'ByID')] + [uint32[]]$Id, + + [Parameter(ParameterSetName = 'Query')] + [string]$Query, + + [Parameter(ParameterSetName = 'Query')] + [string]$Slug, + + [Parameter(ParameterSetName = 'Query')] + [string]$Description, + + [Parameter(ParameterSetName = 'Query')] + [uint16]$Limit, + + [Parameter(ParameterSetName = 'Query')] + [uint16]$Offset, + + [switch]$Raw + ) + + switch ($PSCmdlet.ParameterSetName) { + 'ById' { + foreach ($ContactRole_ID in $Id) { + $Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contact-roles', $ContactRole_ID)) + + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id' + + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters + + InvokeNetboxRequest -URI $uri -Raw:$Raw + } + + break + } + + default { + $Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contact-roles')) + + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters + + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters + + InvokeNetboxRequest -URI $uri -Raw:$Raw + + break + } + } +} \ No newline at end of file From 458a4ae7c28e166f366fa4a86d67fe6d31a1c724 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Wed, 15 Feb 2023 15:42:09 -0500 Subject: [PATCH 03/14] Add New-NetboxContact function --- .../Tenancy/Contacts/New-NetboxContact.ps1 | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 Functions/Tenancy/Contacts/New-NetboxContact.ps1 diff --git a/Functions/Tenancy/Contacts/New-NetboxContact.ps1 b/Functions/Tenancy/Contacts/New-NetboxContact.ps1 new file mode 100644 index 0000000..0e0bf02 --- /dev/null +++ b/Functions/Tenancy/Contacts/New-NetboxContact.ps1 @@ -0,0 +1,99 @@ + +function New-NetboxContact { +<# + .SYNOPSIS + Create a new contact in Netbox + + .DESCRIPTION + Creates a new contact object in Netbox which can be linked to other objects + + .PARAMETER Name + The contacts full name, e.g "Leroy Jenkins" + + .PARAMETER Email + Email address of the contact + + .PARAMETER Title + Job title or other title related to the contact + + .PARAMETER Phone + Telephone number + + .PARAMETER Address + Physical address, usually mailing address + + .PARAMETER Description + Short description of the contact + + .PARAMETER Comments + Detailed comments. Markdown supported. + + .PARAMETER Link + URI related to the contact + + .PARAMETER Custom_Fields + A description of the Custom_Fields parameter. + + .PARAMETER Raw + A description of the Raw parameter. + + .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)] + [ValidateLength(1, 100)] + [string]$Name, + + [Parameter(Mandatory = $true)] + [ValidateLength(0, 254)] + [string]$Email, + + [ValidateLength(0, 100)] + [string]$Title, + + [ValidateLength(0, 50)] + [string]$Phone, + + [ValidateLength(0, 200)] + [string]$Address, + + [ValidateLength(0, 200)] + [string]$Description, + + [string]$Comments, + + [ValidateLength(0, 200)] + [string]$Link, + + [hashtable]$Custom_Fields, + + [switch]$Raw + ) + + process { + $Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contacts')) + $Method = 'POST' + + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters + + $URI = BuildNewURI -Segments $URIComponents.Segments + + if ($PSCmdlet.ShouldProcess($Address, 'Create new contact')) { + InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw + } + } +} + + + + From c91d5fd32caa6e043297ce51ee105be163bae200 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Wed, 15 Feb 2023 15:42:37 -0500 Subject: [PATCH 04/14] Add New-NetboxContactRole function --- .../ContactRoles/New-NetboxContactRole.ps1 | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Functions/Tenancy/ContactRoles/New-NetboxContactRole.ps1 diff --git a/Functions/Tenancy/ContactRoles/New-NetboxContactRole.ps1 b/Functions/Tenancy/ContactRoles/New-NetboxContactRole.ps1 new file mode 100644 index 0000000..740383a --- /dev/null +++ b/Functions/Tenancy/ContactRoles/New-NetboxContactRole.ps1 @@ -0,0 +1,71 @@ + +function New-NetboxContactRole { +<# + .SYNOPSIS + Create a new contact role in Netbox + + .DESCRIPTION + Creates a new contact role object 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)] + [ValidateLength(1, 100)] + [string]$Name, + + [Parameter(Mandatory = $true)] + [ValidateLength(1, 100)] + [ValidatePattern('^[-a-zA-Z0-9_]+$')] + [string]$Slug, + + [ValidateLength(0, 200)] + [string]$Description, + + [hashtable]$Custom_Fields, + + [switch]$Raw + ) + + process { + $Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contacts')) + $Method = 'POST' + + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters + + $URI = BuildNewURI -Segments $URIComponents.Segments + + if ($PSCmdlet.ShouldProcess($Address, 'Create new contact')) { + InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw + } + } +} + + + + From 049745554eaee116078694125832b7fef9728a47 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Wed, 15 Feb 2023 15:43:12 -0500 Subject: [PATCH 05/14] Update psproj --- NetboxPS.psproj | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/NetboxPS.psproj b/NetboxPS.psproj index c37e1db..c9842bc 100644 --- a/NetboxPS.psproj +++ b/NetboxPS.psproj @@ -1,7 +1,9 @@ - + 2.1 bba9b06c-49c8-47cf-8358-aca7c4e78896 1 + True + Local Machine - PowerShell V5 (64 Bit) Functions Functions\DCIM @@ -28,6 +30,9 @@ Functions\Circuits\Providers Functions\Circuits\Types Functions\Circuits\Terminations + Functions\Tenancy\Contacts + Functions\Tenancy\Tenants + Functions\Tenancy\ContactRoles NetboxPS.psd1 @@ -114,6 +119,10 @@ Functions\Setup\Set-NetboxTimeout.ps1 Functions\Setup\Get-NetboxTimeout.ps1 Functions\Setup\Get-NetboxVersion.ps1 + Functions\Tenancy\Contacts\Get-NetboxContact.ps1 + Functions\Tenancy\Contacts\New-NetboxContact.ps1 + Functions\Tenancy\ContactRoles\Get-NetboxContactRole.ps1 + Functions\Tenancy\ContactRoles\New-NetboxContactRole.ps1 R:\Netbox\NetboxPS\Test-Module.ps1 \ No newline at end of file From c0e18ec13431994a00ddca269f156cb0a53be3f0 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Wed, 15 Feb 2023 15:49:29 -0500 Subject: [PATCH 06/14] Move Get-NetboxTenant file to Tenancy/Tenants folder --- Functions/Tenancy/{ => Tenants}/Get-NetboxTenant.ps1 | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Functions/Tenancy/{ => Tenants}/Get-NetboxTenant.ps1 (100%) diff --git a/Functions/Tenancy/Get-NetboxTenant.ps1 b/Functions/Tenancy/Tenants/Get-NetboxTenant.ps1 similarity index 100% rename from Functions/Tenancy/Get-NetboxTenant.ps1 rename to Functions/Tenancy/Tenants/Get-NetboxTenant.ps1 From b720c03851db5ccbc92622f9d43b6a2e0b680295 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Wed, 15 Feb 2023 15:49:49 -0500 Subject: [PATCH 07/14] Add New-NetboxTenant function --- .../Tenancy/Tenants/New-NetboxTenant.ps1 | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Functions/Tenancy/Tenants/New-NetboxTenant.ps1 diff --git a/Functions/Tenancy/Tenants/New-NetboxTenant.ps1 b/Functions/Tenancy/Tenants/New-NetboxTenant.ps1 new file mode 100644 index 0000000..6f7da0f --- /dev/null +++ b/Functions/Tenancy/Tenants/New-NetboxTenant.ps1 @@ -0,0 +1,71 @@ + +function New-NetboxTenant { +<# + .SYNOPSIS + Create a new tenant in Netbox + + .DESCRIPTION + Creates a new tenant object in Netbox + + .PARAMETER Name + The tenant name, e.g "Contoso Inc" + + .PARAMETER Slug + The unique URL for the tenant. Can only contain hypens, A-Z, a-z, 0-9, and underscores + + .PARAMETER Description + Short description of the tenant + + .PARAMETER Custom_Fields + Hashtable of custom field values. + + .PARAMETER Raw + Return the unparsed data from the HTTP request + + .EXAMPLE + PS C:\> New-NetboxTenant -Name 'Contoso Inc' -Slug 'contoso-inc' + + .NOTES + Additional information about the function. +#> + + [CmdletBinding(ConfirmImpact = 'Low', + SupportsShouldProcess = $true)] + [OutputType([pscustomobject])] + param + ( + [Parameter(Mandatory = $true, + ValueFromPipelineByPropertyName = $true)] + [ValidateLength(1, 100)] + [string]$Name, + + [Parameter(Mandatory = $true)] + [ValidateLength(1, 100)] + [ValidatePattern('^[-a-zA-Z0-9_]+$')] + [string]$Slug, + + [ValidateLength(0, 200)] + [string]$Description, + + [hashtable]$Custom_Fields, + + [switch]$Raw + ) + + process { + $Segments = [System.Collections.ArrayList]::new(@('tenancy', 'tenants')) + $Method = 'POST' + + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters + + $URI = BuildNewURI -Segments $URIComponents.Segments + + if ($PSCmdlet.ShouldProcess($Address, 'Create new tenant')) { + InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw + } + } +} + + + + From 8b8ca091b1c835dddcb14d47249982112a116b72 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Wed, 15 Feb 2023 15:50:05 -0500 Subject: [PATCH 08/14] Update psproj --- NetboxPS.psproj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NetboxPS.psproj b/NetboxPS.psproj index c9842bc..a795f7f 100644 --- a/NetboxPS.psproj +++ b/NetboxPS.psproj @@ -73,7 +73,7 @@ Functions\IPAM\Prefix\New-NetboxIPAMPrefix.ps1 Functions\IPAM\Address\Remove-NetboxIPAMAddress.ps1 Functions\IPAM\Address\Set-NetboxIPAMAddress.ps1 - Functions\Tenancy\Get-NetboxTenant.ps1 + Functions\Tenancy\Tenants\Get-NetboxTenant.ps1 Functions\Virtualization\VirtualMachine\Get-NetboxVirtualMachine.ps1 Functions\Virtualization\VirtualMachine\New-NetboxVirtualMachine.ps1 Functions\Virtualization\VirtualMachine\Set-NetboxVirtualMachine.ps1 @@ -123,6 +123,7 @@ Functions\Tenancy\Contacts\New-NetboxContact.ps1 Functions\Tenancy\ContactRoles\Get-NetboxContactRole.ps1 Functions\Tenancy\ContactRoles\New-NetboxContactRole.ps1 + Functions\Tenancy\Tenants\New-NetboxTenant.ps1 R:\Netbox\NetboxPS\Test-Module.ps1 \ No newline at end of file From 4a0bd1d2d054c41d56323e4f86cd32d5a367334b Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Thu, 16 Feb 2023 09:44:29 -0500 Subject: [PATCH 09/14] Add Get-NetboxContentType --- .../Setup/Support/Get-NetboxContentType.ps1 | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 Functions/Setup/Support/Get-NetboxContentType.ps1 diff --git a/Functions/Setup/Support/Get-NetboxContentType.ps1 b/Functions/Setup/Support/Get-NetboxContentType.ps1 new file mode 100644 index 0000000..192a6f2 --- /dev/null +++ b/Functions/Setup/Support/Get-NetboxContentType.ps1 @@ -0,0 +1,89 @@ +function Get-NetboxContentType { +<# + .SYNOPSIS + Get a content type definition from Netbox + + .DESCRIPTION + A detailed description of the Get-NetboxContentType function. + + .PARAMETER Model + A description of the Model parameter. + + .PARAMETER Id + The database ID of the contact role + + .PARAMETER App_Label + A description of the App_Label parameter. + + .PARAMETER Query + A standard search query that will match one or more contact roles. + + .PARAMETER Limit + Limit the number of results to this number + + .PARAMETER Offset + Start the search at this index in results + + .PARAMETER Raw + Return the unparsed data from the HTTP request + + .EXAMPLE + PS C:\> Get-NetboxContentType + + .NOTES + Additional information about the function. +#> + + [CmdletBinding(DefaultParameterSetName = 'Query')] + param + ( + [Parameter(ParameterSetName = 'Query', + Position = 0)] + [string]$Model, + + [Parameter(ParameterSetName = 'ByID')] + [uint32[]]$Id, + + [Parameter(ParameterSetName = 'Query')] + [string]$App_Label, + + [Parameter(ParameterSetName = 'Query')] + [string]$Query, + + [Parameter(ParameterSetName = 'Query')] + [uint16]$Limit, + + [Parameter(ParameterSetName = 'Query')] + [uint16]$Offset, + + [switch]$Raw + ) + + switch ($PSCmdlet.ParameterSetName) { + 'ById' { + foreach ($ContentType_ID in $Id) { + $Segments = [System.Collections.ArrayList]::new(@('extras', 'content-types', $ContentType_ID)) + + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id' + + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters + + InvokeNetboxRequest -URI $uri -Raw:$Raw + } + + break + } + + default { + $Segments = [System.Collections.ArrayList]::new(@('extras', 'content-types')) + + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters + + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters + + InvokeNetboxRequest -URI $uri -Raw:$Raw + + break + } + } +} \ No newline at end of file From 1ec38d3da24135047b97fc36c044cbe2601e2b77 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Thu, 16 Feb 2023 09:45:51 -0500 Subject: [PATCH 10/14] Add call to Get-NetboxContentType in Connect-NetboxAPI and NetboxConfigVariable storage --- Functions/Setup/Connect-NetboxAPI.ps1 | 4 +++- Functions/Setup/Support/SetupNetboxConfigVariable.ps1 | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Functions/Setup/Connect-NetboxAPI.ps1 b/Functions/Setup/Connect-NetboxAPI.ps1 index 5626dfb..974cfc6 100644 --- a/Functions/Setup/Connect-NetboxAPI.ps1 +++ b/Functions/Setup/Connect-NetboxAPI.ps1 @@ -144,7 +144,9 @@ } else { Write-Verbose "Found compatible version [$($script:NetboxConfig.NetboxVersion.'netbox-version')]!" } - + + $script:NetboxConfig.ContentTypes = Get-NetboxContentType -Limit 500 + $script:NetboxConfig.Connected = $true Write-Verbose "Successfully connected!" diff --git a/Functions/Setup/Support/SetupNetboxConfigVariable.ps1 b/Functions/Setup/Support/SetupNetboxConfigVariable.ps1 index a8ac41f..12e5e9c 100644 --- a/Functions/Setup/Support/SetupNetboxConfigVariable.ps1 +++ b/Functions/Setup/Support/SetupNetboxConfigVariable.ps1 @@ -13,6 +13,7 @@ 'Choices' = @{ } 'APIDefinition' = $null + 'ContentTypes' = $null } } From c47d78744735cc00d50e237fa1ab759e2c79d780 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Thu, 16 Feb 2023 09:46:27 -0500 Subject: [PATCH 11/14] Add Get-NetboxContactAssignment --- .../Get-NetboxContactAssignment.ps1 | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 Functions/Tenancy/ContactAssignment/Get-NetboxContactAssignment.ps1 diff --git a/Functions/Tenancy/ContactAssignment/Get-NetboxContactAssignment.ps1 b/Functions/Tenancy/ContactAssignment/Get-NetboxContactAssignment.ps1 new file mode 100644 index 0000000..1f4e0e1 --- /dev/null +++ b/Functions/Tenancy/ContactAssignment/Get-NetboxContactAssignment.ps1 @@ -0,0 +1,108 @@ + +function Get-NetboxContactAssignment { +<# + .SYNOPSIS + Get a contact Assignment from Netbox + + .DESCRIPTION + A detailed description of the Get-NetboxContactAssignment function. + + .PARAMETER Name + The specific name of the contact Assignment. Must match exactly as is defined in Netbox + + .PARAMETER Id + The database ID of the contact Assignment + + .PARAMETER Content_Type_Id + A description of the Content_Type_Id parameter. + + .PARAMETER Content_Type + A description of the Content_Type parameter. + + .PARAMETER Object_Id + A description of the Object_Id parameter. + + .PARAMETER Contact_Id + A description of the Contact_Id parameter. + + .PARAMETER Role_Id + A description of the Role_Id parameter. + + .PARAMETER Limit + Limit the number of results to this number + + .PARAMETER Offset + Start the search at this index in results + + .PARAMETER Raw + Return the unparsed data from the HTTP request + + .EXAMPLE + PS C:\> Get-NetboxContactAssignment + + .NOTES + Additional information about the function. +#> + + [CmdletBinding(DefaultParameterSetName = 'Query')] + param + ( + [Parameter(ParameterSetName = 'Query', + Position = 0)] + [string]$Name, + + [Parameter(ParameterSetName = 'ByID')] + [uint32[]]$Id, + + [Parameter(ParameterSetName = 'Query')] + [uint32]$Content_Type_Id, + + [Parameter(ParameterSetName = 'Query')] + [string]$Content_Type, + + [Parameter(ParameterSetName = 'Query')] + [uint32]$Object_Id, + + [Parameter(ParameterSetName = 'Query')] + [uint32]$Contact_Id, + + [Parameter(ParameterSetName = 'Query')] + [uint32]$Role_Id, + + [Parameter(ParameterSetName = 'Query')] + [uint16]$Limit, + + [Parameter(ParameterSetName = 'Query')] + [uint16]$Offset, + + [switch]$Raw + ) + + switch ($PSCmdlet.ParameterSetName) { + 'ById' { + foreach ($ContactAssignment_ID in $Id) { + $Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contact-assignments', $ContactAssignment_ID)) + + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id' + + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters + + InvokeNetboxRequest -URI $uri -Raw:$Raw + } + + break + } + + default { + $Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contact-assignments')) + + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters + + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters + + InvokeNetboxRequest -URI $uri -Raw:$Raw + + break + } + } +} \ No newline at end of file From 35916a5ab7d0a706abebe072ad56aa78437f36c0 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Thu, 16 Feb 2023 09:47:00 -0500 Subject: [PATCH 12/14] Add New-NetboxContactAssignment --- .../New-NetboxContactAssignment.ps1 | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 Functions/Tenancy/ContactAssignment/New-NetboxContactAssignment.ps1 diff --git a/Functions/Tenancy/ContactAssignment/New-NetboxContactAssignment.ps1 b/Functions/Tenancy/ContactAssignment/New-NetboxContactAssignment.ps1 new file mode 100644 index 0000000..9bc6a7c --- /dev/null +++ b/Functions/Tenancy/ContactAssignment/New-NetboxContactAssignment.ps1 @@ -0,0 +1,108 @@ + +function New-NetboxContactRole { +<# + .SYNOPSIS + Create a new contact role in Netbox + + .DESCRIPTION + Creates a new contact role object in Netbox + + .PARAMETER Content_Type + A description of the Content_Type parameter. + + .PARAMETER Object_Id + A description of the Object_Id parameter. + + .PARAMETER Contact + A description of the Contact parameter. + + .PARAMETER Role + A description of the Role parameter. + + .PARAMETER Priority + A description of the Priority parameter. + + .PARAMETER Raw + Return the unparsed data from the HTTP request + + .EXAMPLE + PS C:\> New-NetboxContactAssignment -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)] + [object]$Content_Type, + + [Parameter(Mandatory = $true)] + [uint32]$Object_Id, + + [Parameter(Mandatory = $true)] + [uint32]$Contact, + + [Parameter(Mandatory = $true)] + [uint32]$Role, + + [ValidateSet('primary', 'secondary', 'tertiary', 'inactive', IgnoreCase = $true)] + [string]$Priority, + + [switch]$Raw + ) + + 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" + } + } + + process { + $Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contact-assignment')) + $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 + + $URI = BuildNewURI -Segments $URIComponents.Segments + + if ($PSCmdlet.ShouldProcess($Address, 'Create new contact assignment')) { + InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw + } + } +} + + + + From f5c94b206f5113270db6fa3a08ae23b596713801 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Thu, 16 Feb 2023 09:48:06 -0500 Subject: [PATCH 13/14] Update psproj --- NetboxPS.psproj | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NetboxPS.psproj b/NetboxPS.psproj index a795f7f..bad6789 100644 --- a/NetboxPS.psproj +++ b/NetboxPS.psproj @@ -33,6 +33,7 @@ Functions\Tenancy\Contacts Functions\Tenancy\Tenants Functions\Tenancy\ContactRoles + Functions\Tenancy\ContactAssignment NetboxPS.psd1 @@ -124,6 +125,10 @@ Functions\Tenancy\ContactRoles\Get-NetboxContactRole.ps1 Functions\Tenancy\ContactRoles\New-NetboxContactRole.ps1 Functions\Tenancy\Tenants\New-NetboxTenant.ps1 + Functions\Tenancy\ContactAssignment\Get-NetboxContactAssignment.ps1 + Functions\Setup\Support\Get-NetboxContentType.ps1 + Functions\Setup\Support\Initialize-NetboxContentTypeEnum.ps1 + Functions\Tenancy\ContactAssignment\New-NetboxContactAssignment.ps1 R:\Netbox\NetboxPS\Test-Module.ps1 \ No newline at end of file From 356bd71ac852c3ab0ecf945e5322a0d5157ed7a8 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Thu, 16 Feb 2023 09:48:35 -0500 Subject: [PATCH 14/14] Remove invalid logic from deploy.ps1 --- deploy.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/deploy.ps1 b/deploy.ps1 index b79da4f..c272fd9 100644 --- a/deploy.ps1 +++ b/deploy.ps1 @@ -157,7 +157,5 @@ if ($ResetCurrentEnvironment) { Write-Warning "Running commands to reset current environment" Write-Host " Reimporting module" Import-Module $PSM1OutputPath, $PSD1OutputPath -Force -ErrorAction Stop - Write-Host " Connecting to VivantioAPI" - Connect-VivantioAPI -Credential $VivantioAPICredential -ODataURI 'https://neonet.vivantio.com/odata/' -RPCURI 'https://webservices-na01.vivantio.com/api/' -ErrorAction Stop Write-Host "Reset complete" -ForegroundColor Green }