From b4781f264a608fe1c8a07791b1f5bc90935237a2 Mon Sep 17 00:00:00 2001 From: Pascal Liehne Date: Sat, 31 Aug 2024 22:52:21 +0200 Subject: [PATCH 1/5] run deploy.ps1 --- .../ContactRoles/Set-NetboxContactRole.ps1 | 26 +++++----- NetboxPS.psd1 | 49 +++++++++---------- NetboxPS/NetboxPS.psd1 | 49 +++++++++---------- NetboxPS/NetboxPS.psm1 | 24 ++++----- 4 files changed, 73 insertions(+), 75 deletions(-) diff --git a/Functions/Tenancy/ContactRoles/Set-NetboxContactRole.ps1 b/Functions/Tenancy/ContactRoles/Set-NetboxContactRole.ps1 index 955ab44..ccd7427 100644 --- a/Functions/Tenancy/ContactRoles/Set-NetboxContactRole.ps1 +++ b/Functions/Tenancy/ContactRoles/Set-NetboxContactRole.ps1 @@ -1,4 +1,4 @@ - + function Set-NetboxContactRole { <# .SYNOPSIS @@ -28,7 +28,7 @@ function Set-NetboxContactRole { .NOTES Additional information about the function. #> - + [CmdletBinding(ConfirmImpact = 'Low', SupportsShouldProcess = $true)] [OutputType([pscustomobject])] @@ -37,37 +37,37 @@ function Set-NetboxContactRole { [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 } diff --git a/NetboxPS.psd1 b/NetboxPS.psd1 index cedd9fa..3f03e75 100644 --- a/NetboxPS.psd1 +++ b/NetboxPS.psd1 @@ -1,9 +1,9 @@ # -# Module manifest for module 'NetboxPS' +# Module manifest for module 'PSGet_NetboxPS' # # Generated by: Ben Claussen # -# Generated on: 2023-11-09 +# Generated on: 31/08/2024 # @{ @@ -66,15 +66,18 @@ CLRVersion = '2.0.50727' # FormatsToProcess = @() # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess -NestedModules = @() +# NestedModules = @() # Functions 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 functions to export. FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface', 'Add-NetboxDCIMInterfaceConnection', 'Add-NetboxDCIMRearPort', - 'Add-NetboxVirtualMachineInterface', 'Clear-NetboxCredential', - 'Connect-NetboxAPI', 'Get-ModelDefinition', 'Get-NetboxAPIDefinition', - 'Get-NetboxCircuit', 'Get-NetboxCircuitProvider', - 'Get-NetboxCircuitTermination', 'Get-NetboxCircuitType', + 'Add-NetboxVirtualMachineInterface', 'BuildNewURI', + 'BuildURIComponents', 'CheckNetboxIsConnected', + 'Clear-NetboxCredential', 'Connect-NetboxAPI', 'CreateEnum', + 'Get-ModelDefinition', 'Get-NetboxAPIDefinition', + 'GetNetboxAPIErrorBody', 'Get-NetboxCircuit', + 'Get-NetboxCircuitProvider', 'Get-NetboxCircuitTermination', + 'Get-NetboxCircuitType', 'GetNetboxConfigVariable', 'Get-NetboxContact', 'Get-NetboxContactAssignment', 'Get-NetboxContactRole', 'Get-NetboxContentType', 'Get-NetboxCredential', 'Get-NetboxDCIMCable', @@ -91,13 +94,14 @@ FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface', 'Get-NetboxTenant', 'Get-NetboxTimeout', 'Get-NetboxVersion', 'Get-NetboxVirtualizationCluster', 'Get-NetboxVirtualizationClusterGroup', 'Get-NetboxVirtualMachine', - 'Get-NetboxVirtualMachineInterface', 'New-NetboxCircuit', - 'New-NetboxContact', 'New-NetboxContactAssignment', - 'New-NetboxContactRole', 'New-NetboxDCIMDevice', 'New-NetboxDCIMSite', - 'New-NetboxIPAMAddress', 'New-NetboxIPAMAddressRange', - 'New-NetboxIPAMPrefix', 'New-NetboxIPAMVLAN', 'New-NetboxTenant', - 'New-NetboxVirtualMachine', 'Remove-NetboxDCIMDevice', - 'Remove-NetboxDCIMFrontPort', 'Remove-NetboxDCIMInterface', + 'Get-NetboxVirtualMachineInterface', 'InvokeNetboxRequest', + 'New-NetboxCircuit', 'New-NetboxContact', + 'New-NetboxContactAssignment', 'New-NetboxContactRole', + 'New-NetboxDCIMDevice', 'New-NetboxDCIMSite', 'New-NetboxIPAMAddress', + 'New-NetboxIPAMAddressRange', 'New-NetboxIPAMPrefix', + 'New-NetboxIPAMVLAN', 'New-NetboxTenant', 'New-NetboxVirtualMachine', + 'Remove-NetboxDCIMDevice', 'Remove-NetboxDCIMFrontPort', + 'Remove-NetboxDCIMInterface', 'Remove-NetboxDCIMInterfaceConnection', 'Remove-NetboxDCIMRearPort', 'Remove-NetboxDCIMSite', 'Remove-NetboxIPAMAddress', 'Remove-NetboxIPAMAddressRange', 'Remove-NetboxVirtualMachine', @@ -111,16 +115,17 @@ FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface', 'Set-NetboxIPAMAddressRange', 'Set-NetboxIPAMPrefix', 'Set-NetboxTimeout', 'Set-NetboxUnstrustedSSL', 'Set-NetboxVirtualMachine', 'Set-NetboxVirtualMachineInterface', - 'Test-NetboxAPIConnected' + 'SetupNetboxConfigVariable', 'Test-NetboxAPIConnected', + 'ThrowNetboxRESTError', 'VerifyAPIConnectivity' # 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 = @() # Variables to export from this module -VariablesToExport = '*' +# VariablesToExport = @() # Aliases 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 aliases to export. -AliasesToExport = '*' +AliasesToExport = @() # DSC resources to export from this module # DscResourcesToExport = @() @@ -151,14 +156,8 @@ PrivateData = @{ # ReleaseNotes of this module # ReleaseNotes = '' - # Prerelease string of this module - # Prerelease = '' - - # Flag to indicate whether the module requires explicit user acceptance for install/update/save - # RequireLicenseAcceptance = $false - # External dependent modules of this module - # ExternalModuleDependencies = @() + # ExternalModuleDependencies = '' } # End of PSData hashtable diff --git a/NetboxPS/NetboxPS.psd1 b/NetboxPS/NetboxPS.psd1 index cedd9fa..3f03e75 100644 --- a/NetboxPS/NetboxPS.psd1 +++ b/NetboxPS/NetboxPS.psd1 @@ -1,9 +1,9 @@ # -# Module manifest for module 'NetboxPS' +# Module manifest for module 'PSGet_NetboxPS' # # Generated by: Ben Claussen # -# Generated on: 2023-11-09 +# Generated on: 31/08/2024 # @{ @@ -66,15 +66,18 @@ CLRVersion = '2.0.50727' # FormatsToProcess = @() # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess -NestedModules = @() +# NestedModules = @() # Functions 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 functions to export. FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface', 'Add-NetboxDCIMInterfaceConnection', 'Add-NetboxDCIMRearPort', - 'Add-NetboxVirtualMachineInterface', 'Clear-NetboxCredential', - 'Connect-NetboxAPI', 'Get-ModelDefinition', 'Get-NetboxAPIDefinition', - 'Get-NetboxCircuit', 'Get-NetboxCircuitProvider', - 'Get-NetboxCircuitTermination', 'Get-NetboxCircuitType', + 'Add-NetboxVirtualMachineInterface', 'BuildNewURI', + 'BuildURIComponents', 'CheckNetboxIsConnected', + 'Clear-NetboxCredential', 'Connect-NetboxAPI', 'CreateEnum', + 'Get-ModelDefinition', 'Get-NetboxAPIDefinition', + 'GetNetboxAPIErrorBody', 'Get-NetboxCircuit', + 'Get-NetboxCircuitProvider', 'Get-NetboxCircuitTermination', + 'Get-NetboxCircuitType', 'GetNetboxConfigVariable', 'Get-NetboxContact', 'Get-NetboxContactAssignment', 'Get-NetboxContactRole', 'Get-NetboxContentType', 'Get-NetboxCredential', 'Get-NetboxDCIMCable', @@ -91,13 +94,14 @@ FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface', 'Get-NetboxTenant', 'Get-NetboxTimeout', 'Get-NetboxVersion', 'Get-NetboxVirtualizationCluster', 'Get-NetboxVirtualizationClusterGroup', 'Get-NetboxVirtualMachine', - 'Get-NetboxVirtualMachineInterface', 'New-NetboxCircuit', - 'New-NetboxContact', 'New-NetboxContactAssignment', - 'New-NetboxContactRole', 'New-NetboxDCIMDevice', 'New-NetboxDCIMSite', - 'New-NetboxIPAMAddress', 'New-NetboxIPAMAddressRange', - 'New-NetboxIPAMPrefix', 'New-NetboxIPAMVLAN', 'New-NetboxTenant', - 'New-NetboxVirtualMachine', 'Remove-NetboxDCIMDevice', - 'Remove-NetboxDCIMFrontPort', 'Remove-NetboxDCIMInterface', + 'Get-NetboxVirtualMachineInterface', 'InvokeNetboxRequest', + 'New-NetboxCircuit', 'New-NetboxContact', + 'New-NetboxContactAssignment', 'New-NetboxContactRole', + 'New-NetboxDCIMDevice', 'New-NetboxDCIMSite', 'New-NetboxIPAMAddress', + 'New-NetboxIPAMAddressRange', 'New-NetboxIPAMPrefix', + 'New-NetboxIPAMVLAN', 'New-NetboxTenant', 'New-NetboxVirtualMachine', + 'Remove-NetboxDCIMDevice', 'Remove-NetboxDCIMFrontPort', + 'Remove-NetboxDCIMInterface', 'Remove-NetboxDCIMInterfaceConnection', 'Remove-NetboxDCIMRearPort', 'Remove-NetboxDCIMSite', 'Remove-NetboxIPAMAddress', 'Remove-NetboxIPAMAddressRange', 'Remove-NetboxVirtualMachine', @@ -111,16 +115,17 @@ FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface', 'Set-NetboxIPAMAddressRange', 'Set-NetboxIPAMPrefix', 'Set-NetboxTimeout', 'Set-NetboxUnstrustedSSL', 'Set-NetboxVirtualMachine', 'Set-NetboxVirtualMachineInterface', - 'Test-NetboxAPIConnected' + 'SetupNetboxConfigVariable', 'Test-NetboxAPIConnected', + 'ThrowNetboxRESTError', 'VerifyAPIConnectivity' # 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 = @() # Variables to export from this module -VariablesToExport = '*' +# VariablesToExport = @() # Aliases 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 aliases to export. -AliasesToExport = '*' +AliasesToExport = @() # DSC resources to export from this module # DscResourcesToExport = @() @@ -151,14 +156,8 @@ PrivateData = @{ # ReleaseNotes of this module # ReleaseNotes = '' - # Prerelease string of this module - # Prerelease = '' - - # Flag to indicate whether the module requires explicit user acceptance for install/update/save - # RequireLicenseAcceptance = $false - # External dependent modules of this module - # ExternalModuleDependencies = @() + # ExternalModuleDependencies = '' } # End of PSData hashtable diff --git a/NetboxPS/NetboxPS.psm1 b/NetboxPS/NetboxPS.psm1 index 6c8d7e2..640c622 100644 --- a/NetboxPS/NetboxPS.psm1 +++ b/NetboxPS/NetboxPS.psm1 @@ -5294,7 +5294,7 @@ function Set-NetboxContactRole { .NOTES Additional information about the function. #> - + [CmdletBinding(ConfirmImpact = 'Low', SupportsShouldProcess = $true)] [OutputType([pscustomobject])] @@ -5303,37 +5303,37 @@ function Set-NetboxContactRole { [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 } From bc8d140ec53eebd2d8d5c5a24806e5420bf889bf Mon Sep 17 00:00:00 2001 From: Pascal Liehne Date: Sun, 1 Sep 2024 00:25:46 +0200 Subject: [PATCH 2/5] Fix Tests/common.ps: credential.ps1 must be loaded before params are prepared --- .../{Get-NetboxContentType.ps1 => Get-NetboxObjectType.ps1} | 0 Tests/common.ps1 | 6 +++--- 2 files changed, 3 insertions(+), 3 deletions(-) rename Functions/Setup/Support/{Get-NetboxContentType.ps1 => Get-NetboxObjectType.ps1} (100%) diff --git a/Functions/Setup/Support/Get-NetboxContentType.ps1 b/Functions/Setup/Support/Get-NetboxObjectType.ps1 similarity index 100% rename from Functions/Setup/Support/Get-NetboxContentType.ps1 rename to Functions/Setup/Support/Get-NetboxObjectType.ps1 diff --git a/Tests/common.ps1 b/Tests/common.ps1 index 116dc24..ad23eef 100644 --- a/Tests/common.ps1 +++ b/Tests/common.ps1 @@ -8,12 +8,12 @@ Param() $script:pester_site1 = "pester_site1" +. ../credential.ps1 +#TODO: Add check if no ipaddress/token info... + $Credential = New-Object System.Management.Automation.PSCredential("username", (ConvertTo-SecureString $token -AsPlainText -Force)) $script:invokeParams = @{ hostname = $hostname; Credential = $Credential; SkipCertificateCheck = $true; } - -. ../credential.ps1 -#TODO: Add check if no ipaddress/token info... \ No newline at end of file From db1bc1e91d8c93f764277d7e58f00d3b186457ca Mon Sep 17 00:00:00 2001 From: Pascal Liehne Date: Sun, 1 Sep 2024 00:32:18 +0200 Subject: [PATCH 3/5] rename ContentTypes to ObjectTypes --- Functions/Setup/Connect-NetboxAPI.ps1 | 2 +- .../Setup/Support/Get-NetboxObjectType.ps1 | 14 +- .../Support/SetupNetboxConfigVariable.ps1 | 2 +- NetboxPS.psd1 | 26 +-- NetboxPS/NetboxPS.psd1 | 26 +-- NetboxPS/NetboxPS.psm1 | 192 +++++++++--------- 6 files changed, 131 insertions(+), 131 deletions(-) diff --git a/Functions/Setup/Connect-NetboxAPI.ps1 b/Functions/Setup/Connect-NetboxAPI.ps1 index 89e900c..bb36287 100644 --- a/Functions/Setup/Connect-NetboxAPI.ps1 +++ b/Functions/Setup/Connect-NetboxAPI.ps1 @@ -148,7 +148,7 @@ $script:NetboxConfig.Connected = $true Write-Verbose "Successfully connected!" - $script:NetboxConfig.ContentTypes = Get-NetboxContentType -Limit 500 + $script:NetboxConfig.ObjectTypes = Get-NetboxObjectType -Limit 500 Write-Verbose "Connection process completed" } \ No newline at end of file diff --git a/Functions/Setup/Support/Get-NetboxObjectType.ps1 b/Functions/Setup/Support/Get-NetboxObjectType.ps1 index 84859fb..ad8dca8 100644 --- a/Functions/Setup/Support/Get-NetboxObjectType.ps1 +++ b/Functions/Setup/Support/Get-NetboxObjectType.ps1 @@ -1,10 +1,10 @@ -function Get-NetboxContentType { +function Get-NetboxObjectType { <# .SYNOPSIS - Get a content type definition from Netbox + Get a object type definition from Netbox .DESCRIPTION - A detailed description of the Get-NetboxContentType function. + A detailed description of the Get-NetboxObjectType function. .PARAMETER Model A description of the Model parameter. @@ -28,7 +28,7 @@ Return the unparsed data from the HTTP request .EXAMPLE - PS C:\> Get-NetboxContentType + PS C:\> Get-NetboxObjectType .NOTES Additional information about the function. @@ -61,8 +61,8 @@ switch ($PSCmdlet.ParameterSetName) { 'ById' { - foreach ($ContentType_ID in $Id) { - $Segments = [System.Collections.ArrayList]::new(@('extras', 'content-types', $ContentType_ID)) + foreach ($ObjectType_ID in $Id) { + $Segments = [System.Collections.ArrayList]::new(@('extras', 'object-types', $ObjectType_ID)) $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id' @@ -75,7 +75,7 @@ } default { - $Segments = [System.Collections.ArrayList]::new(@('extras', 'content-types')) + $Segments = [System.Collections.ArrayList]::new(@('extras', 'object-types')) $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters diff --git a/Functions/Setup/Support/SetupNetboxConfigVariable.ps1 b/Functions/Setup/Support/SetupNetboxConfigVariable.ps1 index 12e5e9c..006d593 100644 --- a/Functions/Setup/Support/SetupNetboxConfigVariable.ps1 +++ b/Functions/Setup/Support/SetupNetboxConfigVariable.ps1 @@ -13,7 +13,7 @@ 'Choices' = @{ } 'APIDefinition' = $null - 'ContentTypes' = $null + 'ObjectTypes' = $null } } diff --git a/NetboxPS.psd1 b/NetboxPS.psd1 index 3f03e75..ac2c422 100644 --- a/NetboxPS.psd1 +++ b/NetboxPS.psd1 @@ -79,19 +79,19 @@ FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface', 'Get-NetboxCircuitProvider', 'Get-NetboxCircuitTermination', 'Get-NetboxCircuitType', 'GetNetboxConfigVariable', 'Get-NetboxContact', 'Get-NetboxContactAssignment', - 'Get-NetboxContactRole', 'Get-NetboxContentType', - 'Get-NetboxCredential', 'Get-NetboxDCIMCable', - 'Get-NetboxDCIMCableTermination', 'Get-NetboxDCIMDevice', - 'Get-NetboxDCIMDeviceRole', 'Get-NetboxDCIMDeviceType', - 'Get-NetboxDCIMFrontPort', 'Get-NetboxDCIMInterface', - 'Get-NetboxDCIMInterfaceConnection', 'Get-NetboxDCIMPlatform', - 'Get-NetboxDCIMRearPort', 'Get-NetboxDCIMSite', 'Get-NetboxHostname', - 'Get-NetboxHostPort', 'Get-NetboxHostScheme', - 'Get-NetboxInvokeParams', 'Get-NetboxIPAMAddress', - 'Get-NetboxIPAMAddressRange', 'Get-NetboxIPAMAggregate', - 'Get-NetboxIPAMAvailableIP', 'Get-NetboxIPAMPrefix', - 'Get-NetboxIPAMRole', 'Get-NetboxIPAMVLAN', 'Get-NetboxTag', - 'Get-NetboxTenant', 'Get-NetboxTimeout', 'Get-NetboxVersion', + 'Get-NetboxContactRole', 'Get-NetboxCredential', + 'Get-NetboxDCIMCable', 'Get-NetboxDCIMCableTermination', + 'Get-NetboxDCIMDevice', 'Get-NetboxDCIMDeviceRole', + 'Get-NetboxDCIMDeviceType', 'Get-NetboxDCIMFrontPort', + 'Get-NetboxDCIMInterface', 'Get-NetboxDCIMInterfaceConnection', + 'Get-NetboxDCIMPlatform', 'Get-NetboxDCIMRearPort', + 'Get-NetboxDCIMSite', 'Get-NetboxHostname', 'Get-NetboxHostPort', + 'Get-NetboxHostScheme', 'Get-NetboxInvokeParams', + 'Get-NetboxIPAMAddress', 'Get-NetboxIPAMAddressRange', + 'Get-NetboxIPAMAggregate', 'Get-NetboxIPAMAvailableIP', + 'Get-NetboxIPAMPrefix', 'Get-NetboxIPAMRole', 'Get-NetboxIPAMVLAN', + 'Get-NetboxObjectType', 'Get-NetboxTag', 'Get-NetboxTenant', + 'Get-NetboxTimeout', 'Get-NetboxVersion', 'Get-NetboxVirtualizationCluster', 'Get-NetboxVirtualizationClusterGroup', 'Get-NetboxVirtualMachine', 'Get-NetboxVirtualMachineInterface', 'InvokeNetboxRequest', diff --git a/NetboxPS/NetboxPS.psd1 b/NetboxPS/NetboxPS.psd1 index 3f03e75..ac2c422 100644 --- a/NetboxPS/NetboxPS.psd1 +++ b/NetboxPS/NetboxPS.psd1 @@ -79,19 +79,19 @@ FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface', 'Get-NetboxCircuitProvider', 'Get-NetboxCircuitTermination', 'Get-NetboxCircuitType', 'GetNetboxConfigVariable', 'Get-NetboxContact', 'Get-NetboxContactAssignment', - 'Get-NetboxContactRole', 'Get-NetboxContentType', - 'Get-NetboxCredential', 'Get-NetboxDCIMCable', - 'Get-NetboxDCIMCableTermination', 'Get-NetboxDCIMDevice', - 'Get-NetboxDCIMDeviceRole', 'Get-NetboxDCIMDeviceType', - 'Get-NetboxDCIMFrontPort', 'Get-NetboxDCIMInterface', - 'Get-NetboxDCIMInterfaceConnection', 'Get-NetboxDCIMPlatform', - 'Get-NetboxDCIMRearPort', 'Get-NetboxDCIMSite', 'Get-NetboxHostname', - 'Get-NetboxHostPort', 'Get-NetboxHostScheme', - 'Get-NetboxInvokeParams', 'Get-NetboxIPAMAddress', - 'Get-NetboxIPAMAddressRange', 'Get-NetboxIPAMAggregate', - 'Get-NetboxIPAMAvailableIP', 'Get-NetboxIPAMPrefix', - 'Get-NetboxIPAMRole', 'Get-NetboxIPAMVLAN', 'Get-NetboxTag', - 'Get-NetboxTenant', 'Get-NetboxTimeout', 'Get-NetboxVersion', + 'Get-NetboxContactRole', 'Get-NetboxCredential', + 'Get-NetboxDCIMCable', 'Get-NetboxDCIMCableTermination', + 'Get-NetboxDCIMDevice', 'Get-NetboxDCIMDeviceRole', + 'Get-NetboxDCIMDeviceType', 'Get-NetboxDCIMFrontPort', + 'Get-NetboxDCIMInterface', 'Get-NetboxDCIMInterfaceConnection', + 'Get-NetboxDCIMPlatform', 'Get-NetboxDCIMRearPort', + 'Get-NetboxDCIMSite', 'Get-NetboxHostname', 'Get-NetboxHostPort', + 'Get-NetboxHostScheme', 'Get-NetboxInvokeParams', + 'Get-NetboxIPAMAddress', 'Get-NetboxIPAMAddressRange', + 'Get-NetboxIPAMAggregate', 'Get-NetboxIPAMAvailableIP', + 'Get-NetboxIPAMPrefix', 'Get-NetboxIPAMRole', 'Get-NetboxIPAMVLAN', + 'Get-NetboxObjectType', 'Get-NetboxTag', 'Get-NetboxTenant', + 'Get-NetboxTimeout', 'Get-NetboxVersion', 'Get-NetboxVirtualizationCluster', 'Get-NetboxVirtualizationClusterGroup', 'Get-NetboxVirtualMachine', 'Get-NetboxVirtualMachineInterface', 'InvokeNetboxRequest', diff --git a/NetboxPS/NetboxPS.psm1 b/NetboxPS/NetboxPS.psm1 index 640c622..e444b2c 100644 --- a/NetboxPS/NetboxPS.psm1 +++ b/NetboxPS/NetboxPS.psm1 @@ -615,7 +615,7 @@ function Connect-NetboxAPI { $script:NetboxConfig.Connected = $true Write-Verbose "Successfully connected!" - $script:NetboxConfig.ContentTypes = Get-NetboxContentType -Limit 500 + $script:NetboxConfig.ObjectTypes = Get-NetboxObjectType -Limit 500 Write-Verbose "Connection process completed" } @@ -1411,100 +1411,6 @@ function Get-NetboxContactRole { #endregion -#region File Get-NetboxContentType.ps1 - -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')] - [uint64[]]$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 - } - } -} - -#endregion - #region File Get-NetboxCredential.ps1 function Get-NetboxCredential { @@ -2908,6 +2814,100 @@ function Get-NetboxIPAMVLAN { +#endregion + +#region File Get-NetboxObjectType.ps1 + +function Get-NetboxObjectType { +<# + .SYNOPSIS + Get a object type definition from Netbox + + .DESCRIPTION + A detailed description of the Get-NetboxObjectType 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-NetboxObjectType + + .NOTES + Additional information about the function. +#> + + [CmdletBinding(DefaultParameterSetName = 'Query')] + param + ( + [Parameter(ParameterSetName = 'Query', + Position = 0)] + [string]$Model, + + [Parameter(ParameterSetName = 'ByID')] + [uint64[]]$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 ($ObjectType_ID in $Id) { + $Segments = [System.Collections.ArrayList]::new(@('extras', 'object-types', $ObjectType_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', 'object-types')) + + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters + + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters + + InvokeNetboxRequest -URI $uri -Raw:$Raw + + break + } + } +} + #endregion #region File Get-NetboxTag.ps1 @@ -6272,7 +6272,7 @@ function SetupNetboxConfigVariable { 'Choices' = @{ } 'APIDefinition' = $null - 'ContentTypes' = $null + 'ObjectTypes' = $null } } From 3abf2264d95885297a4a880410012cac5c21b1fa Mon Sep 17 00:00:00 2001 From: Pascal Liehne Date: Sun, 1 Sep 2024 01:34:53 +0200 Subject: [PATCH 4/5] set new minimum Netbox version number --- Functions/Setup/Connect-NetboxAPI.ps1 | 6 +++--- NetboxPS.psd1 | 2 +- NetboxPS/NetboxPS.psd1 | 2 +- NetboxPS/NetboxPS.psm1 | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Functions/Setup/Connect-NetboxAPI.ps1 b/Functions/Setup/Connect-NetboxAPI.ps1 index bb36287..4e1e429 100644 --- a/Functions/Setup/Connect-NetboxAPI.ps1 +++ b/Functions/Setup/Connect-NetboxAPI.ps1 @@ -138,9 +138,9 @@ Write-Verbose "Checking Netbox version compatibility" $script:NetboxConfig.NetboxVersion = Get-NetboxVersion - if ([version]$script:NetboxConfig.NetboxVersion.'netbox-version' -lt 2.8) { + if ([version]$script:NetboxConfig.NetboxVersion.'netbox-version' -lt 4.0.1) { $Script:NetboxConfig.Connected = $false - throw "Netbox version is incompatible with this PS module. Requires >=2.8.*, found version $($script:NetboxConfig.NetboxVersion.'netbox-version')" + throw "Netbox version is incompatible with this PS module. Requires >=4.0, found version $($script:NetboxConfig.NetboxVersion.'netbox-version')" } else { Write-Verbose "Found compatible version [$($script:NetboxConfig.NetboxVersion.'netbox-version')]!" } @@ -151,4 +151,4 @@ $script:NetboxConfig.ObjectTypes = Get-NetboxObjectType -Limit 500 Write-Verbose "Connection process completed" -} \ No newline at end of file +} diff --git a/NetboxPS.psd1 b/NetboxPS.psd1 index ac2c422..22fc1f7 100644 --- a/NetboxPS.psd1 +++ b/NetboxPS.psd1 @@ -3,7 +3,7 @@ # # Generated by: Ben Claussen # -# Generated on: 31/08/2024 +# Generated on: 01/09/2024 # @{ diff --git a/NetboxPS/NetboxPS.psd1 b/NetboxPS/NetboxPS.psd1 index ac2c422..22fc1f7 100644 --- a/NetboxPS/NetboxPS.psd1 +++ b/NetboxPS/NetboxPS.psd1 @@ -3,7 +3,7 @@ # # Generated by: Ben Claussen # -# Generated on: 31/08/2024 +# Generated on: 01/09/2024 # @{ diff --git a/NetboxPS/NetboxPS.psm1 b/NetboxPS/NetboxPS.psm1 index e444b2c..f8e63e0 100644 --- a/NetboxPS/NetboxPS.psm1 +++ b/NetboxPS/NetboxPS.psm1 @@ -605,9 +605,9 @@ function Connect-NetboxAPI { Write-Verbose "Checking Netbox version compatibility" $script:NetboxConfig.NetboxVersion = Get-NetboxVersion - if ([version]$script:NetboxConfig.NetboxVersion.'netbox-version' -lt 2.8) { + if ([version]$script:NetboxConfig.NetboxVersion.'netbox-version' -lt 4.0.1) { $Script:NetboxConfig.Connected = $false - throw "Netbox version is incompatible with this PS module. Requires >=2.8.*, found version $($script:NetboxConfig.NetboxVersion.'netbox-version')" + throw "Netbox version is incompatible with this PS module. Requires >=4.0, found version $($script:NetboxConfig.NetboxVersion.'netbox-version')" } else { Write-Verbose "Found compatible version [$($script:NetboxConfig.NetboxVersion.'netbox-version')]!" } From f3bcb9f616304969da282818783168850775add2 Mon Sep 17 00:00:00 2001 From: Pascal Liehne Date: Sun, 1 Sep 2024 18:48:14 +0200 Subject: [PATCH 5/5] add Site to Set-NetboxVirtualMachine --- .../VirtualMachine/Set-NetboxVirtualMachine.ps1 | 4 +++- NetboxPS/NetboxPS.psm1 | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Functions/Virtualization/VirtualMachine/Set-NetboxVirtualMachine.ps1 b/Functions/Virtualization/VirtualMachine/Set-NetboxVirtualMachine.ps1 index 3b722b4..5decc3f 100644 --- a/Functions/Virtualization/VirtualMachine/Set-NetboxVirtualMachine.ps1 +++ b/Functions/Virtualization/VirtualMachine/Set-NetboxVirtualMachine.ps1 @@ -12,6 +12,8 @@ function Set-NetboxVirtualMachine { [uint64]$Role, + [uint64]$Site, + [uint64]$Cluster, [object]$Status, @@ -58,4 +60,4 @@ function Set-NetboxVirtualMachine { InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH } } -} \ No newline at end of file +} diff --git a/NetboxPS/NetboxPS.psm1 b/NetboxPS/NetboxPS.psm1 index f8e63e0..671f7fc 100644 --- a/NetboxPS/NetboxPS.psm1 +++ b/NetboxPS/NetboxPS.psm1 @@ -6148,6 +6148,8 @@ function Set-NetboxVirtualMachine { [uint64]$Role, + [uint64]$Site, + [uint64]$Cluster, [object]$Status,