From b164ffe0b45b7a42e410b1b16723e9e3b3b4a7a3 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Wed, 21 Jul 2021 22:06:00 +0200 Subject: [PATCH 01/68] Connect(Setup): Fix indent (using Visual code Formatter) --- Functions/Setup/Connect-NetboxAPI.ps1 | 61 ++++++++++++++------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/Functions/Setup/Connect-NetboxAPI.ps1 b/Functions/Setup/Connect-NetboxAPI.ps1 index 1b27c12..4244f2a 100644 --- a/Functions/Setup/Connect-NetboxAPI.ps1 +++ b/Functions/Setup/Connect-NetboxAPI.ps1 @@ -1,75 +1,76 @@ function Connect-NetboxAPI { -<# + <# .SYNOPSIS Connects to the Netbox API and ensures Credential work properly - + .DESCRIPTION Connects to the Netbox API and ensures Credential work properly - + .PARAMETER Hostname The hostname for the resource such as netbox.domain.com - + .PARAMETER Credential Credential object containing the API key in the password. Username is not applicable - + .PARAMETER Scheme Scheme for the URI such as HTTP or HTTPS. Defaults to HTTPS - + .PARAMETER Port Port for the resource. Value between 1-65535 - + .PARAMETER URI The full URI for the resource such as "https://netbox.domain.com:8443" - + .EXAMPLE PS C:\> Connect-NetboxAPI -Hostname "netbox.domain.com" - + This will prompt for Credential, then proceed to attempt a connection to Netbox - + .NOTES Additional information about the function. #> - + [CmdletBinding(DefaultParameterSetName = 'Manual')] param ( [Parameter(ParameterSetName = 'Manual', Mandatory = $true)] [string]$Hostname, - + [Parameter(Mandatory = $false)] [pscredential]$Credential, - + [Parameter(ParameterSetName = 'Manual')] [ValidateSet('https', 'http', IgnoreCase = $true)] [string]$Scheme = 'https', - + [Parameter(ParameterSetName = 'Manual')] [uint16]$Port = 443, - + [Parameter(ParameterSetName = 'URI', Mandatory = $true)] [string]$URI ) - + if (-not $Credential) { try { $Credential = Get-NetboxCredential -ErrorAction Stop - } catch { + } + catch { # Credentials are not set... Try to obtain from the user if (-not ($Credential = Get-Credential -UserName 'username-not-applicable' -Message "Enter token for Netbox")) { throw "Token is necessary to connect to a Netbox API." } } } - + $null = Set-NetboxCredential -Credential $Credential - + switch ($PSCmdlet.ParameterSetName) { 'Manual' { $uriBuilder = [System.UriBuilder]::new($Scheme, $Hostname, $Port) } - + 'URI' { $uriBuilder = [System.UriBuilder]::new($URI) if ([string]::IsNullOrWhiteSpace($uriBuilder.Host)) { @@ -77,35 +78,37 @@ } } } - + $null = Set-NetboxHostName -Hostname $uriBuilder.Host $null = Set-NetboxHostScheme -Scheme $uriBuilder.Scheme $null = Set-NetboxHostPort -Port $uriBuilder.Port - + try { Write-Verbose "Verifying API connectivity..." $null = VerifyAPIConnectivity - } catch { + } + catch { Write-Verbose "Failed to connect. Generating error" Write-Verbose $_.Exception.Message if (($_.Exception.Response) -and ($_.Exception.Response.StatusCode -eq 403)) { throw "Invalid token" - } else { + } + else { throw $_ } } - + Write-Verbose "Caching API definition" $script:NetboxConfig.APIDefinition = Get-NetboxAPIDefinition - + if ([version]$script:NetboxConfig.APIDefinition.info.version -lt 2.8) { $Script:NetboxConfig.Connected = $false throw "Netbox version is incompatible with this PS module. Requires >=2.8.*, found version $($script:NetboxConfig.APIDefinition.info.version)" } - + $script:NetboxConfig.Connected = $true Write-Verbose "Successfully connected!" - + #Write-Verbose "Caching static choices" #$script:NetboxConfig.Choices.Circuits = Get-NetboxCircuitsChoices #$script:NetboxConfig.Choices.DCIM = Get-NetboxDCIMChoices # Not completed yet @@ -114,6 +117,6 @@ ##$script:NetboxConfig.Choices.Secrets = Get-NetboxSecretsChoices # Not completed yet ##$script:NetboxConfig.Choices.Tenancy = Get-NetboxTenancyChoices #$script:NetboxConfig.Choices.Virtualization = Get-NetboxVirtualizationChoices - + Write-Verbose "Connection process completed" } \ No newline at end of file From 5b1ee457690fd7a98b9e56ed3c3b3f70dae0756b Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Wed, 21 Jul 2021 22:19:45 +0200 Subject: [PATCH 02/68] Setup(Functions): Fix indent (using Visual Code Formatter) --- Functions/Setup/Get-NetboxCredential.ps1 | 4 ++-- Functions/Setup/Get-NetboxHostname.ps1 | 4 ++-- Functions/Setup/Set-NetboxCredential.ps1 | 16 ++++++++-------- Functions/Setup/Set-NetboxHostName.ps1 | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Functions/Setup/Get-NetboxCredential.ps1 b/Functions/Setup/Get-NetboxCredential.ps1 index 25f0eb9..a1235fb 100644 --- a/Functions/Setup/Get-NetboxCredential.ps1 +++ b/Functions/Setup/Get-NetboxCredential.ps1 @@ -2,10 +2,10 @@ [CmdletBinding()] [OutputType([pscredential])] param () - + if (-not $script:NetboxConfig.Credential) { throw "Netbox Credentials not set! You may set with Set-NetboxCredential" } - + $script:NetboxConfig.Credential } \ No newline at end of file diff --git a/Functions/Setup/Get-NetboxHostname.ps1 b/Functions/Setup/Get-NetboxHostname.ps1 index 0629541..63a8c3f 100644 --- a/Functions/Setup/Get-NetboxHostname.ps1 +++ b/Functions/Setup/Get-NetboxHostname.ps1 @@ -1,11 +1,11 @@ function Get-NetboxHostname { [CmdletBinding()] param () - + Write-Verbose "Getting Netbox hostname" if ($null -eq $script:NetboxConfig.Hostname) { throw "Netbox Hostname is not set! You may set it with Set-NetboxHostname -Hostname 'hostname.domain.tld'" } - + $script:NetboxConfig.Hostname } \ No newline at end of file diff --git a/Functions/Setup/Set-NetboxCredential.ps1 b/Functions/Setup/Set-NetboxCredential.ps1 index 448f272..dcbb24a 100644 --- a/Functions/Setup/Set-NetboxCredential.ps1 +++ b/Functions/Setup/Set-NetboxCredential.ps1 @@ -1,32 +1,32 @@ function Set-NetboxCredential { [CmdletBinding(DefaultParameterSetName = 'CredsObject', - ConfirmImpact = 'Low', - SupportsShouldProcess = $true)] + ConfirmImpact = 'Low', + SupportsShouldProcess = $true)] [OutputType([pscredential])] param ( [Parameter(ParameterSetName = 'CredsObject', - Mandatory = $true)] + Mandatory = $true)] [pscredential]$Credential, - + [Parameter(ParameterSetName = 'UserPass', - Mandatory = $true)] + Mandatory = $true)] [securestring]$Token ) - + if ($PSCmdlet.ShouldProcess('Netbox Credentials', 'Set')) { switch ($PsCmdlet.ParameterSetName) { 'CredsObject' { $script:NetboxConfig.Credential = $Credential break } - + 'UserPass' { $script:NetboxConfig.Credential = [System.Management.Automation.PSCredential]::new('notapplicable', $Token) break } } - + $script:NetboxConfig.Credential } } \ No newline at end of file diff --git a/Functions/Setup/Set-NetboxHostName.ps1 b/Functions/Setup/Set-NetboxHostName.ps1 index 92b9dbe..a70c055 100644 --- a/Functions/Setup/Set-NetboxHostName.ps1 +++ b/Functions/Setup/Set-NetboxHostName.ps1 @@ -1,13 +1,13 @@ function Set-NetboxHostName { [CmdletBinding(ConfirmImpact = 'Low', - SupportsShouldProcess = $true)] + SupportsShouldProcess = $true)] [OutputType([string])] param ( [Parameter(Mandatory = $true)] [string]$Hostname ) - + if ($PSCmdlet.ShouldProcess('Netbox Hostname', 'Set')) { $script:NetboxConfig.Hostname = $Hostname.Trim() $script:NetboxConfig.Hostname From 4ad05624662b8380d40fa4ff6aaee5e426f94d0d Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Wed, 21 Jul 2021 22:22:28 +0200 Subject: [PATCH 03/68] Support(Setup): Fix indent (using Visual Code Formatter) --- .../Setup/Support/Get-NetboxAPIDefinition.ps1 | 26 +++++++++---------- .../Support/SetupNetboxConfigVariable.ps1 | 8 +++--- .../Setup/Support/VerifyAPIConnectivity.ps1 | 8 +++--- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Functions/Setup/Support/Get-NetboxAPIDefinition.ps1 b/Functions/Setup/Support/Get-NetboxAPIDefinition.ps1 index 3fb0215..21315c8 100644 --- a/Functions/Setup/Support/Get-NetboxAPIDefinition.ps1 +++ b/Functions/Setup/Support/Get-NetboxAPIDefinition.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.174 @@ -14,16 +14,16 @@ function Get-NetboxAPIDefinition { - [CmdletBinding()] - param () - - #$URI = "https://netbox.neonet.org/api/docs/?format=openapi" - - $Segments = [System.Collections.ArrayList]::new(@('docs')) - - $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary @{'format' = 'openapi'} - - $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters -SkipConnectedCheck - - InvokeNetboxRequest -URI $URI -Timeout 10 + [CmdletBinding()] + param () + + #$URI = "https://netbox.neonet.org/api/docs/?format=openapi" + + $Segments = [System.Collections.ArrayList]::new(@('docs')) + + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary @{'format' = 'openapi' } + + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters -SkipConnectedCheck + + InvokeNetboxRequest -URI $URI -Timeout 10 } diff --git a/Functions/Setup/Support/SetupNetboxConfigVariable.ps1 b/Functions/Setup/Support/SetupNetboxConfigVariable.ps1 index 20d84a8..a8ac41f 100644 --- a/Functions/Setup/Support/SetupNetboxConfigVariable.ps1 +++ b/Functions/Setup/Support/SetupNetboxConfigVariable.ps1 @@ -4,17 +4,17 @@ ( [switch]$Overwrite ) - + Write-Verbose "Checking for NetboxConfig hashtable" if ((-not ($script:NetboxConfig)) -or $Overwrite) { Write-Verbose "Creating NetboxConfig hashtable" $script:NetboxConfig = @{ - 'Connected' = $false - 'Choices' = @{ + 'Connected' = $false + 'Choices' = @{ } 'APIDefinition' = $null } } - + Write-Verbose "NetboxConfig hashtable already exists" } \ No newline at end of file diff --git a/Functions/Setup/Support/VerifyAPIConnectivity.ps1 b/Functions/Setup/Support/VerifyAPIConnectivity.ps1 index b53760e..fb8d9d1 100644 --- a/Functions/Setup/Support/VerifyAPIConnectivity.ps1 +++ b/Functions/Setup/Support/VerifyAPIConnectivity.ps1 @@ -1,10 +1,10 @@ function VerifyAPIConnectivity { [CmdletBinding()] param () - + $uriSegments = [System.Collections.ArrayList]::new(@('extras')) - - $uri = BuildNewURI -Segments $uriSegments -Parameters @{'format' = 'json'} -SkipConnectedCheck - + + $uri = BuildNewURI -Segments $uriSegments -Parameters @{'format' = 'json' } -SkipConnectedCheck + InvokeNetboxRequest -URI $uri } \ No newline at end of file From 2bf4ed6f6fc482ba694c6d41daf5dcfdf65fd9b4 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Wed, 21 Jul 2021 22:22:59 +0200 Subject: [PATCH 04/68] InvokeNetboxRequest(Helpers): Fix indent (using Visual Code Formatter) --- Functions/Helpers/InvokeNetboxRequest.ps1 | 54 ++++++++++++----------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/Functions/Helpers/InvokeNetboxRequest.ps1 b/Functions/Helpers/InvokeNetboxRequest.ps1 index ef5d31e..d5c55f6 100644 --- a/Functions/Helpers/InvokeNetboxRequest.ps1 +++ b/Functions/Helpers/InvokeNetboxRequest.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -18,44 +18,44 @@ function InvokeNetboxRequest { ( [Parameter(Mandatory = $true)] [System.UriBuilder]$URI, - + [Hashtable]$Headers = @{ }, - + [pscustomobject]$Body = $null, - + [ValidateRange(0, 60)] [uint16]$Timeout = 5, - + [ValidateSet('GET', 'PATCH', 'PUT', 'POST', 'DELETE', 'OPTIONS', IgnoreCase = $true)] [string]$Method = 'GET', - + [switch]$Raw ) - + $creds = Get-NetboxCredential - + $Headers.Authorization = "Token {0}" -f $creds.GetNetworkCredential().Password - + $splat = @{ - 'Method' = $Method - 'Uri' = $URI.Uri.AbsoluteUri # This property auto generates the scheme, hostname, path, and query - 'Headers' = $Headers - 'TimeoutSec' = $Timeout + 'Method' = $Method + 'Uri' = $URI.Uri.AbsoluteUri # This property auto generates the scheme, hostname, path, and query + 'Headers' = $Headers + 'TimeoutSec' = $Timeout 'ContentType' = 'application/json' 'ErrorAction' = 'Stop' - 'Verbose' = $VerbosePreference + 'Verbose' = $VerbosePreference } - + if ($Body) { Write-Verbose "BODY: $($Body | ConvertTo-Json -Compress)" $null = $splat.Add('Body', ($Body | ConvertTo-Json -Compress)) } - + $result = Invoke-RestMethod @splat - + #region TODO: Handle errors a little more gracefully... - + <# try { Write-Verbose "Sending request..." @@ -69,7 +69,7 @@ function InvokeNetboxRequest { Write-Verbose "RAW provided...throwing raw exception" throw $_ } - + Write-Verbose "Converting response to object" $myError = GetNetboxAPIErrorBody -Response $_.Exception.Response | ConvertFrom-Json } else { @@ -77,27 +77,29 @@ function InvokeNetboxRequest { $myError = $_ } } - + Write-Verbose "MyError is $($myError.GetType().FullName)" - + if ($myError -is [Exception]) { throw $_ } elseif ($myError -is [pscustomobject]) { throw $myError.detail - } + } #> - + #endregion TODO: Handle errors a little more gracefully... - + # If the user wants the raw value from the API... otherwise return only the actual result if ($Raw) { Write-Verbose "Returning raw result by choice" return $result - } else { + } + else { if ($result.psobject.Properties.Name.Contains('results')) { Write-Verbose "Found Results property on data, returning results directly" return $result.Results - } else { + } + else { Write-Verbose "Did NOT find results property on data, returning raw result" return $result } From c8c6d48ee44026d3d610bc578f7833e63a6299d7 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Wed, 21 Jul 2021 22:35:39 +0200 Subject: [PATCH 05/68] Add Set-netboxCipherSSL for enable TLS1.1 and TLS1.2 (for PS 5.0) From PowerAruba/FortiPower Module :) --- Functions/Setup/Set-NetboxCipherSSL.ps1 | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Functions/Setup/Set-NetboxCipherSSL.ps1 diff --git a/Functions/Setup/Set-NetboxCipherSSL.ps1 b/Functions/Setup/Set-NetboxCipherSSL.ps1 new file mode 100644 index 0000000..bad4402 --- /dev/null +++ b/Functions/Setup/Set-NetboxCipherSSL.ps1 @@ -0,0 +1,8 @@ +Function Set-NetboxCipherSSL { + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessforStateChangingFunctions", "")] + Param( ) + # Hack for allowing TLS 1.1 and TLS 1.2 (by default it is only SSL3 and TLS (1.0)) + $AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12' + [System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols + +} \ No newline at end of file From c8233ab57243902ef7a2af7222765e2dd03c2707 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Wed, 21 Jul 2021 22:36:39 +0200 Subject: [PATCH 06/68] Add Set-NetboxUnstrustedSSL for disable SSL chain test (for PS 5.0 From PowerAruba/FortiPwoer Module :) --- Functions/Setup/Set-NetboxUnstrustedSSL.ps1 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Functions/Setup/Set-NetboxUnstrustedSSL.ps1 diff --git a/Functions/Setup/Set-NetboxUnstrustedSSL.ps1 b/Functions/Setup/Set-NetboxUnstrustedSSL.ps1 new file mode 100644 index 0000000..e118d1c --- /dev/null +++ b/Functions/Setup/Set-NetboxUnstrustedSSL.ps1 @@ -0,0 +1,19 @@ +Function Set-NetboxUntrustedSSL { + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessforStateChangingFunctions", "")] + Param( ) + # Hack for allowing untrusted SSL certs with https connections + Add-Type -TypeDefinition @" + using System.Net; + using System.Security.Cryptography.X509Certificates; + public class TrustAllCertsPolicy : ICertificatePolicy { + public bool CheckValidationResult( + ServicePoint srvPoint, X509Certificate certificate, + WebRequest request, int certificateProblem) { + return true; + } + } +"@ + + [System.Net.ServicePointManager]::CertificatePolicy = New-Object -TypeName TrustAllCertsPolicy + +} \ No newline at end of file From 254a2798ac872ede6152461afe70ad1aad3dfcb3 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Wed, 21 Jul 2021 22:41:26 +0200 Subject: [PATCH 07/68] Add Get/Set netboxInvokeParms for Get and Set Invoke Params (array) Like -SkipCertificate, Timeout... --- Functions/Setup/Get-NetboxInvokeParams.ps1 | 11 +++++++++++ Functions/Setup/Set-NetboxInvokeParams.ps1 | 15 +++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 Functions/Setup/Get-NetboxInvokeParams.ps1 create mode 100644 Functions/Setup/Set-NetboxInvokeParams.ps1 diff --git a/Functions/Setup/Get-NetboxInvokeParams.ps1 b/Functions/Setup/Get-NetboxInvokeParams.ps1 new file mode 100644 index 0000000..0cd33c7 --- /dev/null +++ b/Functions/Setup/Get-NetboxInvokeParams.ps1 @@ -0,0 +1,11 @@ +function Get-NetboxInvokeParams { + [CmdletBinding()] + param () + + Write-Verbose "Getting Netbox InvokeParams" + if ($null -eq $script:NetboxConfig.InvokeParams) { + throw "Netbox Invoke Parms is not set! You may set it with Set-NetboxInvokeParams -InvokeParams ..." + } + + $script:NetboxConfig.InvokeParams +} \ No newline at end of file diff --git a/Functions/Setup/Set-NetboxInvokeParams.ps1 b/Functions/Setup/Set-NetboxInvokeParams.ps1 new file mode 100644 index 0000000..ca5dbf5 --- /dev/null +++ b/Functions/Setup/Set-NetboxInvokeParams.ps1 @@ -0,0 +1,15 @@ +function Set-NetboxInvokeParams { + [CmdletBinding(ConfirmImpact = 'Low', + SupportsShouldProcess = $true)] + [OutputType([string])] + param + ( + [Parameter(Mandatory = $true)] + [array]$InvokeParams + ) + + if ($PSCmdlet.ShouldProcess('Netbox Invoke Params', 'Set')) { + $script:NetboxConfig.InvokeParams = $InvokeParams + $script:NetboxConfig.InvokeParams + } +} \ No newline at end of file From 1a2484db2c0a7c7eed7ae095166208de0b287900 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Wed, 21 Jul 2021 23:00:59 +0200 Subject: [PATCH 08/68] InvokeNetboxRequest: Add to Splat NetboxInvokeParams --- Functions/Helpers/InvokeNetboxRequest.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Functions/Helpers/InvokeNetboxRequest.ps1 b/Functions/Helpers/InvokeNetboxRequest.ps1 index d5c55f6..9a82048 100644 --- a/Functions/Helpers/InvokeNetboxRequest.ps1 +++ b/Functions/Helpers/InvokeNetboxRequest.ps1 @@ -47,6 +47,8 @@ function InvokeNetboxRequest { 'Verbose' = $VerbosePreference } + $splat += Get-NetboxInvokeParams + if ($Body) { Write-Verbose "BODY: $($Body | ConvertTo-Json -Compress)" $null = $splat.Add('Body', ($Body | ConvertTo-Json -Compress)) From 4800cc6564a2ef1889f70c73b2331c8a4c6ab0b9 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Wed, 21 Jul 2021 23:02:18 +0200 Subject: [PATCH 09/68] Connect: Add SkipCertificateCheck parameter (for PS5 and Core) Also enable TLS 1.1 and 1.2 for PS5 --- Functions/Setup/Connect-NetboxAPI.ps1 | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Functions/Setup/Connect-NetboxAPI.ps1 b/Functions/Setup/Connect-NetboxAPI.ps1 index 4244f2a..6bc0d03 100644 --- a/Functions/Setup/Connect-NetboxAPI.ps1 +++ b/Functions/Setup/Connect-NetboxAPI.ps1 @@ -49,7 +49,10 @@ [Parameter(ParameterSetName = 'URI', Mandatory = $true)] - [string]$URI + [string]$URI, + + [Parameter(Mandatory = $false)] + [switch]$SkipCertificateCheck = $false ) if (-not $Credential) { @@ -64,7 +67,22 @@ } } - $null = Set-NetboxCredential -Credential $Credential + $invokeParams = @{ SkipCertificateCheck = $SkipCertificateCheck; } + + if ("Desktop" -eq $PSVersionTable.PsEdition) { + #Remove -SkipCertificateCheck from Invoke Parameter (not supported <= PS 5) + $invokeParams.remove("SkipCertificateCheck") + } + + #for PowerShell (<=) 5 (Desktop), Enable TLS 1.1, 1.2 and Disable SSL chain trust + if ("Desktop" -eq $PSVersionTable.PsEdition) { + #Enable TLS 1.1 and 1.2 + Set-NetboxCipherSSL + if ($SkipCertificateCheck) { + #Disable SSL chain trust... + Set-NetboxuntrustedSSL + } + } switch ($PSCmdlet.ParameterSetName) { 'Manual' { @@ -80,8 +98,10 @@ } $null = Set-NetboxHostName -Hostname $uriBuilder.Host + $null = Set-NetboxCredential -Credential $Credential $null = Set-NetboxHostScheme -Scheme $uriBuilder.Scheme $null = Set-NetboxHostPort -Port $uriBuilder.Port + $null = Set-NetboxInvokeParams -invokeParams $invokeParams try { Write-Verbose "Verifying API connectivity..." From fcbb25c0881eb0a17d5f839274e6497d35156586 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Thu, 22 Jul 2021 15:23:15 +0200 Subject: [PATCH 10/68] PSSA: Add Github Actions for launch PSSA (PowerShell Script Analyzer) when launch PR (#11) Add also vscode/PSScriptAnalyzerSettings.psd1 for Settings for PSSA (can be reuse also for vscode...) --- .github/workflows/pssa.yml | 16 ++++++++++++++++ .vscode/PSScriptAnalyzerSettings.psd1 | 5 +++++ 2 files changed, 21 insertions(+) create mode 100644 .github/workflows/pssa.yml create mode 100644 .vscode/PSScriptAnalyzerSettings.psd1 diff --git a/.github/workflows/pssa.yml b/.github/workflows/pssa.yml new file mode 100644 index 0000000..446a549 --- /dev/null +++ b/.github/workflows/pssa.yml @@ -0,0 +1,16 @@ +name: CI +on: [pull_request] +jobs: + lint: + name: Run PSSA + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: lint + uses: docker://devblackops/github-action-psscriptanalyzer:2.3.0 + with: + settingsPath: .vscode/PSScriptAnalyzerSettings.psd1 + sendComment: false + failOnInfos: true + failOnErrors: true + failOnWarnings: true \ No newline at end of file diff --git a/.vscode/PSScriptAnalyzerSettings.psd1 b/.vscode/PSScriptAnalyzerSettings.psd1 new file mode 100644 index 0000000..311a301 --- /dev/null +++ b/.vscode/PSScriptAnalyzerSettings.psd1 @@ -0,0 +1,5 @@ +@{ + ExcludeRules = @( + 'PSUseToExportFieldsInManifest' + ) +} \ No newline at end of file From 6122fd230141ea5c689cffc8dcd4868752f46214 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Thu, 22 Jul 2021 10:22:19 -0400 Subject: [PATCH 11/68] Update psproj --- NetboxPS.psproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NetboxPS.psproj b/NetboxPS.psproj index 938d28b..60a4dff 100644 --- a/NetboxPS.psproj +++ b/NetboxPS.psproj @@ -108,6 +108,10 @@ Functions\Setup\Get-NetboxHostScheme.ps1 Functions\Setup\Set-NetboxHostPort.ps1 Functions\Setup\Get-NetboxHostPort.ps1 + Functions\Setup\Get-NetboxInvokeParams.ps1 + Functions\Setup\Set-NetboxCipherSSL.ps1 + Functions\Setup\Set-NetboxInvokeParams.ps1 + Functions\Setup\Set-NetboxUnstrustedSSL.ps1 R:\Netbox\NetboxPS\Test-Module.ps1 \ No newline at end of file From 989c5eaac227bfab4dba45226527676f887f47d9 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Thu, 22 Jul 2021 10:27:58 -0400 Subject: [PATCH 12/68] Correct typo --- Functions/Setup/Get-NetboxInvokeParams.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Functions/Setup/Get-NetboxInvokeParams.ps1 b/Functions/Setup/Get-NetboxInvokeParams.ps1 index 0cd33c7..ec95d24 100644 --- a/Functions/Setup/Get-NetboxInvokeParams.ps1 +++ b/Functions/Setup/Get-NetboxInvokeParams.ps1 @@ -4,7 +4,7 @@ function Get-NetboxInvokeParams { Write-Verbose "Getting Netbox InvokeParams" if ($null -eq $script:NetboxConfig.InvokeParams) { - throw "Netbox Invoke Parms is not set! You may set it with Set-NetboxInvokeParams -InvokeParams ..." + throw "Netbox Invoke Params is not set! You may set it with Set-NetboxInvokeParams -InvokeParams ..." } $script:NetboxConfig.InvokeParams From 06d758d7b3b82a49718c4423ab545c4c42ef9624 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Thu, 22 Jul 2021 10:28:22 -0400 Subject: [PATCH 13/68] Correct brace formatting --- Functions/Helpers/InvokeNetboxRequest.ps1 | 6 ++---- Functions/Setup/Connect-NetboxAPI.ps1 | 9 +++------ Functions/Setup/Set-NetboxInvokeParams.ps1 | 3 +-- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/Functions/Helpers/InvokeNetboxRequest.ps1 b/Functions/Helpers/InvokeNetboxRequest.ps1 index 9a82048..5750730 100644 --- a/Functions/Helpers/InvokeNetboxRequest.ps1 +++ b/Functions/Helpers/InvokeNetboxRequest.ps1 @@ -95,13 +95,11 @@ function InvokeNetboxRequest { if ($Raw) { Write-Verbose "Returning raw result by choice" return $result - } - else { + } else { if ($result.psobject.Properties.Name.Contains('results')) { Write-Verbose "Found Results property on data, returning results directly" return $result.Results - } - else { + } else { Write-Verbose "Did NOT find results property on data, returning raw result" return $result } diff --git a/Functions/Setup/Connect-NetboxAPI.ps1 b/Functions/Setup/Connect-NetboxAPI.ps1 index 6bc0d03..e732f16 100644 --- a/Functions/Setup/Connect-NetboxAPI.ps1 +++ b/Functions/Setup/Connect-NetboxAPI.ps1 @@ -58,8 +58,7 @@ if (-not $Credential) { try { $Credential = Get-NetboxCredential -ErrorAction Stop - } - catch { + } catch { # Credentials are not set... Try to obtain from the user if (-not ($Credential = Get-Credential -UserName 'username-not-applicable' -Message "Enter token for Netbox")) { throw "Token is necessary to connect to a Netbox API." @@ -106,14 +105,12 @@ try { Write-Verbose "Verifying API connectivity..." $null = VerifyAPIConnectivity - } - catch { + } catch { Write-Verbose "Failed to connect. Generating error" Write-Verbose $_.Exception.Message if (($_.Exception.Response) -and ($_.Exception.Response.StatusCode -eq 403)) { throw "Invalid token" - } - else { + } else { throw $_ } } diff --git a/Functions/Setup/Set-NetboxInvokeParams.ps1 b/Functions/Setup/Set-NetboxInvokeParams.ps1 index ca5dbf5..b82ef6d 100644 --- a/Functions/Setup/Set-NetboxInvokeParams.ps1 +++ b/Functions/Setup/Set-NetboxInvokeParams.ps1 @@ -2,8 +2,7 @@ function Set-NetboxInvokeParams { [CmdletBinding(ConfirmImpact = 'Low', SupportsShouldProcess = $true)] [OutputType([string])] - param - ( + param( [Parameter(Mandatory = $true)] [array]$InvokeParams ) From c48bfe78ad1fff034d33e56683a4170a6fbe31a6 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Thu, 22 Jul 2021 10:48:41 -0400 Subject: [PATCH 14/68] Add Get/Set timeout functions --- Functions/Setup/Get-NetboxTimeout.ps1 | 13 +++++++++++++ Functions/Setup/Set-NetboxTimeout.ps1 | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 Functions/Setup/Get-NetboxTimeout.ps1 create mode 100644 Functions/Setup/Set-NetboxTimeout.ps1 diff --git a/Functions/Setup/Get-NetboxTimeout.ps1 b/Functions/Setup/Get-NetboxTimeout.ps1 new file mode 100644 index 0000000..7547e33 --- /dev/null +++ b/Functions/Setup/Get-NetboxTimeout.ps1 @@ -0,0 +1,13 @@ + +function Get-NetboxTimeout { + [CmdletBinding()] + [OutputType([uint16])] + param () + + Write-Verbose "Getting Netbox Timeout" + if ($null -eq $script:NetboxConfig.Timeout) { + throw "Netbox Timeout is not set! You may set it with Set-NetboxTimeout -TimeoutSeconds [uint16]" + } + + $script:NetboxConfig.Timeout +} \ No newline at end of file diff --git a/Functions/Setup/Set-NetboxTimeout.ps1 b/Functions/Setup/Set-NetboxTimeout.ps1 new file mode 100644 index 0000000..cee71d2 --- /dev/null +++ b/Functions/Setup/Set-NetboxTimeout.ps1 @@ -0,0 +1,17 @@ + +function Set-NetboxTimeout { + [CmdletBinding(ConfirmImpact = 'Low', + SupportsShouldProcess = $true)] + [OutputType([uint16])] + param + ( + [Parameter(Mandatory = $false)] + [ValidateRange(1, 65535)] + [uint16]$TimeoutSeconds = 30 + ) + + if ($PSCmdlet.ShouldProcess('Netbox Timeout', 'Set')) { + $script:NetboxConfig.Timeout = $TimeoutSeconds + $script:NetboxConfig.Timeout + } +} \ No newline at end of file From 218114d8fee9c50f4a40211c15ec4ddd993e5e28 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Thu, 22 Jul 2021 10:48:41 -0400 Subject: [PATCH 15/68] Add Get/Set timeout functions --- Functions/Setup/Get-NetboxTimeout.ps1 | 13 +++++++++++++ Functions/Setup/Set-NetboxTimeout.ps1 | 17 +++++++++++++++++ NetboxPS.psproj | 2 ++ 3 files changed, 32 insertions(+) create mode 100644 Functions/Setup/Get-NetboxTimeout.ps1 create mode 100644 Functions/Setup/Set-NetboxTimeout.ps1 diff --git a/Functions/Setup/Get-NetboxTimeout.ps1 b/Functions/Setup/Get-NetboxTimeout.ps1 new file mode 100644 index 0000000..7547e33 --- /dev/null +++ b/Functions/Setup/Get-NetboxTimeout.ps1 @@ -0,0 +1,13 @@ + +function Get-NetboxTimeout { + [CmdletBinding()] + [OutputType([uint16])] + param () + + Write-Verbose "Getting Netbox Timeout" + if ($null -eq $script:NetboxConfig.Timeout) { + throw "Netbox Timeout is not set! You may set it with Set-NetboxTimeout -TimeoutSeconds [uint16]" + } + + $script:NetboxConfig.Timeout +} \ No newline at end of file diff --git a/Functions/Setup/Set-NetboxTimeout.ps1 b/Functions/Setup/Set-NetboxTimeout.ps1 new file mode 100644 index 0000000..cee71d2 --- /dev/null +++ b/Functions/Setup/Set-NetboxTimeout.ps1 @@ -0,0 +1,17 @@ + +function Set-NetboxTimeout { + [CmdletBinding(ConfirmImpact = 'Low', + SupportsShouldProcess = $true)] + [OutputType([uint16])] + param + ( + [Parameter(Mandatory = $false)] + [ValidateRange(1, 65535)] + [uint16]$TimeoutSeconds = 30 + ) + + if ($PSCmdlet.ShouldProcess('Netbox Timeout', 'Set')) { + $script:NetboxConfig.Timeout = $TimeoutSeconds + $script:NetboxConfig.Timeout + } +} \ No newline at end of file diff --git a/NetboxPS.psproj b/NetboxPS.psproj index 60a4dff..f78ceb1 100644 --- a/NetboxPS.psproj +++ b/NetboxPS.psproj @@ -112,6 +112,8 @@ Functions\Setup\Set-NetboxCipherSSL.ps1 Functions\Setup\Set-NetboxInvokeParams.ps1 Functions\Setup\Set-NetboxUnstrustedSSL.ps1 + Functions\Setup\Set-NetboxTimeout.ps1 + Functions\Setup\Get-NetboxTimeout.ps1 R:\Netbox\NetboxPS\Test-Module.ps1 \ No newline at end of file From 22607fde48cf21c969647d5f64fb94eee45545f5 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Thu, 22 Jul 2021 11:06:13 -0400 Subject: [PATCH 16/68] Add TimeoutSeconds parameter and logic to Connect-NetboxAPI - Updated `InvokeNetboxRequest` to use `NetboxConfig.Timeout` - Updated `Get-NetboxAPIDefinition` to use `NetboxConfig.Timeout` --- Functions/Helpers/InvokeNetboxRequest.ps1 | 4 +- Functions/Setup/Connect-NetboxAPI.ps1 | 71 +++++++++++-------- .../Setup/Support/Get-NetboxAPIDefinition.ps1 | 2 +- 3 files changed, 44 insertions(+), 33 deletions(-) diff --git a/Functions/Helpers/InvokeNetboxRequest.ps1 b/Functions/Helpers/InvokeNetboxRequest.ps1 index 5750730..9696518 100644 --- a/Functions/Helpers/InvokeNetboxRequest.ps1 +++ b/Functions/Helpers/InvokeNetboxRequest.ps1 @@ -24,8 +24,8 @@ function InvokeNetboxRequest { [pscustomobject]$Body = $null, - [ValidateRange(0, 60)] - [uint16]$Timeout = 5, + [ValidateRange(1, 65535)] + [uint16]$Timeout = (Get-NetboxTimeout), [ValidateSet('GET', 'PATCH', 'PUT', 'POST', 'DELETE', 'OPTIONS', IgnoreCase = $true)] [string]$Method = 'GET', diff --git a/Functions/Setup/Connect-NetboxAPI.ps1 b/Functions/Setup/Connect-NetboxAPI.ps1 index e732f16..70c6457 100644 --- a/Functions/Setup/Connect-NetboxAPI.ps1 +++ b/Functions/Setup/Connect-NetboxAPI.ps1 @@ -1,60 +1,70 @@ function Connect-NetboxAPI { - <# +<# .SYNOPSIS Connects to the Netbox API and ensures Credential work properly - + .DESCRIPTION Connects to the Netbox API and ensures Credential work properly - + .PARAMETER Hostname The hostname for the resource such as netbox.domain.com - + .PARAMETER Credential Credential object containing the API key in the password. Username is not applicable - + .PARAMETER Scheme Scheme for the URI such as HTTP or HTTPS. Defaults to HTTPS - + .PARAMETER Port Port for the resource. Value between 1-65535 - + .PARAMETER URI The full URI for the resource such as "https://netbox.domain.com:8443" - + + .PARAMETER SkipCertificateCheck + A description of the SkipCertificateCheck parameter. + + .PARAMETER TimeoutSeconds + The number of seconds before the HTTP call times out. Defaults to 30 seconds + .EXAMPLE PS C:\> Connect-NetboxAPI -Hostname "netbox.domain.com" - + This will prompt for Credential, then proceed to attempt a connection to Netbox - + .NOTES Additional information about the function. #> - + [CmdletBinding(DefaultParameterSetName = 'Manual')] param ( [Parameter(ParameterSetName = 'Manual', Mandatory = $true)] [string]$Hostname, - + [Parameter(Mandatory = $false)] [pscredential]$Credential, - + [Parameter(ParameterSetName = 'Manual')] [ValidateSet('https', 'http', IgnoreCase = $true)] [string]$Scheme = 'https', - + [Parameter(ParameterSetName = 'Manual')] [uint16]$Port = 443, - + [Parameter(ParameterSetName = 'URI', Mandatory = $true)] [string]$URI, - + [Parameter(Mandatory = $false)] - [switch]$SkipCertificateCheck = $false + [switch]$SkipCertificateCheck = $false, + + [ValidateNotNullOrEmpty()] + [ValidateRange(1, 65535)] + [uint16]$TimeoutSeconds = 30 ) - + if (-not $Credential) { try { $Credential = Get-NetboxCredential -ErrorAction Stop @@ -65,14 +75,14 @@ } } } - + $invokeParams = @{ SkipCertificateCheck = $SkipCertificateCheck; } - + if ("Desktop" -eq $PSVersionTable.PsEdition) { #Remove -SkipCertificateCheck from Invoke Parameter (not supported <= PS 5) $invokeParams.remove("SkipCertificateCheck") } - + #for PowerShell (<=) 5 (Desktop), Enable TLS 1.1, 1.2 and Disable SSL chain trust if ("Desktop" -eq $PSVersionTable.PsEdition) { #Enable TLS 1.1 and 1.2 @@ -82,12 +92,12 @@ Set-NetboxuntrustedSSL } } - + switch ($PSCmdlet.ParameterSetName) { 'Manual' { $uriBuilder = [System.UriBuilder]::new($Scheme, $Hostname, $Port) } - + 'URI' { $uriBuilder = [System.UriBuilder]::new($URI) if ([string]::IsNullOrWhiteSpace($uriBuilder.Host)) { @@ -95,13 +105,14 @@ } } } - + $null = Set-NetboxHostName -Hostname $uriBuilder.Host $null = Set-NetboxCredential -Credential $Credential $null = Set-NetboxHostScheme -Scheme $uriBuilder.Scheme $null = Set-NetboxHostPort -Port $uriBuilder.Port $null = Set-NetboxInvokeParams -invokeParams $invokeParams - + $null = Set-NetboxTimeout -TimeoutSeconds $TimeoutSeconds + try { Write-Verbose "Verifying API connectivity..." $null = VerifyAPIConnectivity @@ -114,18 +125,18 @@ throw $_ } } - + Write-Verbose "Caching API definition" $script:NetboxConfig.APIDefinition = Get-NetboxAPIDefinition - + if ([version]$script:NetboxConfig.APIDefinition.info.version -lt 2.8) { $Script:NetboxConfig.Connected = $false throw "Netbox version is incompatible with this PS module. Requires >=2.8.*, found version $($script:NetboxConfig.APIDefinition.info.version)" } - + $script:NetboxConfig.Connected = $true Write-Verbose "Successfully connected!" - + #Write-Verbose "Caching static choices" #$script:NetboxConfig.Choices.Circuits = Get-NetboxCircuitsChoices #$script:NetboxConfig.Choices.DCIM = Get-NetboxDCIMChoices # Not completed yet @@ -134,6 +145,6 @@ ##$script:NetboxConfig.Choices.Secrets = Get-NetboxSecretsChoices # Not completed yet ##$script:NetboxConfig.Choices.Tenancy = Get-NetboxTenancyChoices #$script:NetboxConfig.Choices.Virtualization = Get-NetboxVirtualizationChoices - + Write-Verbose "Connection process completed" } \ No newline at end of file diff --git a/Functions/Setup/Support/Get-NetboxAPIDefinition.ps1 b/Functions/Setup/Support/Get-NetboxAPIDefinition.ps1 index 21315c8..59ca911 100644 --- a/Functions/Setup/Support/Get-NetboxAPIDefinition.ps1 +++ b/Functions/Setup/Support/Get-NetboxAPIDefinition.ps1 @@ -25,5 +25,5 @@ function Get-NetboxAPIDefinition { $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters -SkipConnectedCheck - InvokeNetboxRequest -URI $URI -Timeout 10 + InvokeNetboxRequest -URI $URI } From ea9f6c41bc5ef049d988a0f4ad5b455f7ded0584 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Thu, 22 Jul 2021 11:39:39 -0400 Subject: [PATCH 17/68] Trim whitespaces --- Functions/Setup/Connect-NetboxAPI.ps1 | 62 +++++++++---------- Functions/Setup/Get-NetboxTimeout.ps1 | 4 +- Functions/Setup/Set-NetboxTimeout.ps1 | 2 +- .../Setup/Support/Get-NetboxAPIDefinition.ps1 | 34 +++++----- 4 files changed, 51 insertions(+), 51 deletions(-) diff --git a/Functions/Setup/Connect-NetboxAPI.ps1 b/Functions/Setup/Connect-NetboxAPI.ps1 index 70c6457..72e84c7 100644 --- a/Functions/Setup/Connect-NetboxAPI.ps1 +++ b/Functions/Setup/Connect-NetboxAPI.ps1 @@ -2,69 +2,69 @@ <# .SYNOPSIS Connects to the Netbox API and ensures Credential work properly - + .DESCRIPTION Connects to the Netbox API and ensures Credential work properly - + .PARAMETER Hostname The hostname for the resource such as netbox.domain.com - + .PARAMETER Credential Credential object containing the API key in the password. Username is not applicable - + .PARAMETER Scheme Scheme for the URI such as HTTP or HTTPS. Defaults to HTTPS - + .PARAMETER Port Port for the resource. Value between 1-65535 - + .PARAMETER URI The full URI for the resource such as "https://netbox.domain.com:8443" - + .PARAMETER SkipCertificateCheck A description of the SkipCertificateCheck parameter. - + .PARAMETER TimeoutSeconds The number of seconds before the HTTP call times out. Defaults to 30 seconds - + .EXAMPLE PS C:\> Connect-NetboxAPI -Hostname "netbox.domain.com" - + This will prompt for Credential, then proceed to attempt a connection to Netbox - + .NOTES Additional information about the function. #> - + [CmdletBinding(DefaultParameterSetName = 'Manual')] param ( [Parameter(ParameterSetName = 'Manual', Mandatory = $true)] [string]$Hostname, - + [Parameter(Mandatory = $false)] [pscredential]$Credential, - + [Parameter(ParameterSetName = 'Manual')] [ValidateSet('https', 'http', IgnoreCase = $true)] [string]$Scheme = 'https', - + [Parameter(ParameterSetName = 'Manual')] [uint16]$Port = 443, - + [Parameter(ParameterSetName = 'URI', Mandatory = $true)] [string]$URI, - + [Parameter(Mandatory = $false)] [switch]$SkipCertificateCheck = $false, - + [ValidateNotNullOrEmpty()] [ValidateRange(1, 65535)] [uint16]$TimeoutSeconds = 30 ) - + if (-not $Credential) { try { $Credential = Get-NetboxCredential -ErrorAction Stop @@ -75,14 +75,14 @@ } } } - + $invokeParams = @{ SkipCertificateCheck = $SkipCertificateCheck; } - + if ("Desktop" -eq $PSVersionTable.PsEdition) { #Remove -SkipCertificateCheck from Invoke Parameter (not supported <= PS 5) $invokeParams.remove("SkipCertificateCheck") } - + #for PowerShell (<=) 5 (Desktop), Enable TLS 1.1, 1.2 and Disable SSL chain trust if ("Desktop" -eq $PSVersionTable.PsEdition) { #Enable TLS 1.1 and 1.2 @@ -92,12 +92,12 @@ Set-NetboxuntrustedSSL } } - + switch ($PSCmdlet.ParameterSetName) { 'Manual' { $uriBuilder = [System.UriBuilder]::new($Scheme, $Hostname, $Port) } - + 'URI' { $uriBuilder = [System.UriBuilder]::new($URI) if ([string]::IsNullOrWhiteSpace($uriBuilder.Host)) { @@ -105,14 +105,14 @@ } } } - + $null = Set-NetboxHostName -Hostname $uriBuilder.Host $null = Set-NetboxCredential -Credential $Credential $null = Set-NetboxHostScheme -Scheme $uriBuilder.Scheme $null = Set-NetboxHostPort -Port $uriBuilder.Port $null = Set-NetboxInvokeParams -invokeParams $invokeParams $null = Set-NetboxTimeout -TimeoutSeconds $TimeoutSeconds - + try { Write-Verbose "Verifying API connectivity..." $null = VerifyAPIConnectivity @@ -125,18 +125,18 @@ throw $_ } } - + Write-Verbose "Caching API definition" $script:NetboxConfig.APIDefinition = Get-NetboxAPIDefinition - + if ([version]$script:NetboxConfig.APIDefinition.info.version -lt 2.8) { $Script:NetboxConfig.Connected = $false throw "Netbox version is incompatible with this PS module. Requires >=2.8.*, found version $($script:NetboxConfig.APIDefinition.info.version)" } - + $script:NetboxConfig.Connected = $true Write-Verbose "Successfully connected!" - + #Write-Verbose "Caching static choices" #$script:NetboxConfig.Choices.Circuits = Get-NetboxCircuitsChoices #$script:NetboxConfig.Choices.DCIM = Get-NetboxDCIMChoices # Not completed yet @@ -145,6 +145,6 @@ ##$script:NetboxConfig.Choices.Secrets = Get-NetboxSecretsChoices # Not completed yet ##$script:NetboxConfig.Choices.Tenancy = Get-NetboxTenancyChoices #$script:NetboxConfig.Choices.Virtualization = Get-NetboxVirtualizationChoices - + Write-Verbose "Connection process completed" } \ No newline at end of file diff --git a/Functions/Setup/Get-NetboxTimeout.ps1 b/Functions/Setup/Get-NetboxTimeout.ps1 index 7547e33..220e3f1 100644 --- a/Functions/Setup/Get-NetboxTimeout.ps1 +++ b/Functions/Setup/Get-NetboxTimeout.ps1 @@ -3,11 +3,11 @@ function Get-NetboxTimeout { [CmdletBinding()] [OutputType([uint16])] param () - + Write-Verbose "Getting Netbox Timeout" if ($null -eq $script:NetboxConfig.Timeout) { throw "Netbox Timeout is not set! You may set it with Set-NetboxTimeout -TimeoutSeconds [uint16]" } - + $script:NetboxConfig.Timeout } \ No newline at end of file diff --git a/Functions/Setup/Set-NetboxTimeout.ps1 b/Functions/Setup/Set-NetboxTimeout.ps1 index cee71d2..a738019 100644 --- a/Functions/Setup/Set-NetboxTimeout.ps1 +++ b/Functions/Setup/Set-NetboxTimeout.ps1 @@ -9,7 +9,7 @@ function Set-NetboxTimeout { [ValidateRange(1, 65535)] [uint16]$TimeoutSeconds = 30 ) - + if ($PSCmdlet.ShouldProcess('Netbox Timeout', 'Set')) { $script:NetboxConfig.Timeout = $TimeoutSeconds $script:NetboxConfig.Timeout diff --git a/Functions/Setup/Support/Get-NetboxAPIDefinition.ps1 b/Functions/Setup/Support/Get-NetboxAPIDefinition.ps1 index 59ca911..4fcdf0c 100644 --- a/Functions/Setup/Support/Get-NetboxAPIDefinition.ps1 +++ b/Functions/Setup/Support/Get-NetboxAPIDefinition.ps1 @@ -1,29 +1,29 @@ <# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.174 - Created on: 4/28/2020 11:57 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxAPIDefinition.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. + .NOTES + =========================================================================== + Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.174 + Created on: 4/28/2020 11:57 + Created by: Claussen + Organization: NEOnet + Filename: Get-NetboxAPIDefinition.ps1 + =========================================================================== + .DESCRIPTION + A description of the file. #> function Get-NetboxAPIDefinition { - [CmdletBinding()] - param () + [CmdletBinding()] + param () - #$URI = "https://netbox.neonet.org/api/docs/?format=openapi" + #$URI = "https://netbox.neonet.org/api/docs/?format=openapi" - $Segments = [System.Collections.ArrayList]::new(@('docs')) + $Segments = [System.Collections.ArrayList]::new(@('docs')) - $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary @{'format' = 'openapi' } + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary @{'format' = 'openapi' } - $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters -SkipConnectedCheck + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters -SkipConnectedCheck - InvokeNetboxRequest -URI $URI + InvokeNetboxRequest -URI $URI } From 17c4d9d779ad0e7d3114c2bbcef3784cdc5a4809 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Thu, 22 Jul 2021 11:51:49 -0400 Subject: [PATCH 18/68] Add Get-NetboxVersion function --- Functions/Setup/Get-NetboxVersion.ps1 | 15 +++++++++++++++ NetboxPS.psproj | 1 + 2 files changed, 16 insertions(+) create mode 100644 Functions/Setup/Get-NetboxVersion.ps1 diff --git a/Functions/Setup/Get-NetboxVersion.ps1 b/Functions/Setup/Get-NetboxVersion.ps1 new file mode 100644 index 0000000..7dc8c03 --- /dev/null +++ b/Functions/Setup/Get-NetboxVersion.ps1 @@ -0,0 +1,15 @@ + +function Get-NetboxVersion { + [CmdletBinding()] + param () + + $Segments = [System.Collections.ArrayList]::new(@('status')) + + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary @{ + 'format' = 'json' + } + + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters -SkipConnectedCheck + + InvokeNetboxRequest -URI $URI +} diff --git a/NetboxPS.psproj b/NetboxPS.psproj index f78ceb1..b71197d 100644 --- a/NetboxPS.psproj +++ b/NetboxPS.psproj @@ -114,6 +114,7 @@ Functions\Setup\Set-NetboxUnstrustedSSL.ps1 Functions\Setup\Set-NetboxTimeout.ps1 Functions\Setup\Get-NetboxTimeout.ps1 + Functions\Setup\Get-NetboxVersion.ps1 R:\Netbox\NetboxPS\Test-Module.ps1 \ No newline at end of file From 68161a78b0330cb2f69913777a35df61b8dd58b0 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Thu, 22 Jul 2021 11:52:57 -0400 Subject: [PATCH 19/68] Remove API Definition caching and replace with Netbox version check --- Functions/Setup/Connect-NetboxAPI.ps1 | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Functions/Setup/Connect-NetboxAPI.ps1 b/Functions/Setup/Connect-NetboxAPI.ps1 index 72e84c7..b012a0f 100644 --- a/Functions/Setup/Connect-NetboxAPI.ps1 +++ b/Functions/Setup/Connect-NetboxAPI.ps1 @@ -126,12 +126,21 @@ } } - Write-Verbose "Caching API definition" - $script:NetboxConfig.APIDefinition = Get-NetboxAPIDefinition +# Write-Verbose "Caching API definition" +# $script:NetboxConfig.APIDefinition = Get-NetboxAPIDefinition +# +# if ([version]$script:NetboxConfig.APIDefinition.info.version -lt 2.8) { +# $Script:NetboxConfig.Connected = $false +# throw "Netbox version is incompatible with this PS module. Requires >=2.8.*, found version $($script:NetboxConfig.APIDefinition.info.version)" + # } - if ([version]$script:NetboxConfig.APIDefinition.info.version -lt 2.8) { + Write-Verbose "Checking Netbox version compatibility" + $script:NetboxConfig.NetboxVersion = Get-NetboxVersion + if ([version]$script:NetboxConfig.NetboxVersion.'netbox-version' -lt 2.8) { $Script:NetboxConfig.Connected = $false - throw "Netbox version is incompatible with this PS module. Requires >=2.8.*, found version $($script:NetboxConfig.APIDefinition.info.version)" + throw "Netbox version is incompatible with this PS module. Requires >=2.8.*, found version $($script:NetboxConfig.NetboxVersion.'netbox-version')" + } else { + Write-Verbose "Found compatible version [$($script:NetboxConfig.NetboxVersion.'netbox-version')]!" } $script:NetboxConfig.Connected = $true From 2b7c1b4be370df4c01a099b43978a9f9b9f6361f Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Thu, 22 Jul 2021 11:53:58 -0400 Subject: [PATCH 20/68] Increment version to 1.4 --- NetboxPS.psd1 | 4 +- NetboxPS/NetboxPS.psd1 | 4 +- NetboxPS/NetboxPS.psm1 | 368 ++++++++++++++++++++++++++++++----------- 3 files changed, 275 insertions(+), 101 deletions(-) diff --git a/NetboxPS.psd1 b/NetboxPS.psd1 index 5601780..ead3b18 100644 --- a/NetboxPS.psd1 +++ b/NetboxPS.psd1 @@ -3,7 +3,7 @@ # # Generated by: Ben Claussen # -# Generated on: 2021-03-31 +# Generated on: 2021-07-22 # @{ @@ -12,7 +12,7 @@ RootModule = 'NetboxPS.psm1' # Version number of this module. -ModuleVersion = '1.3.3' +ModuleVersion = '1.4' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/NetboxPS/NetboxPS.psd1 b/NetboxPS/NetboxPS.psd1 index 5601780..ead3b18 100644 --- a/NetboxPS/NetboxPS.psd1 +++ b/NetboxPS/NetboxPS.psd1 @@ -3,7 +3,7 @@ # # Generated by: Ben Claussen # -# Generated on: 2021-03-31 +# Generated on: 2021-07-22 # @{ @@ -12,7 +12,7 @@ RootModule = 'NetboxPS.psm1' # Version number of this module. -ModuleVersion = '1.3.3' +ModuleVersion = '1.4' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/NetboxPS/NetboxPS.psm1 b/NetboxPS/NetboxPS.psm1 index f500181..61fa4b8 100644 --- a/NetboxPS/NetboxPS.psm1 +++ b/NetboxPS/NetboxPS.psm1 @@ -471,56 +471,69 @@ function Connect-NetboxAPI { <# .SYNOPSIS Connects to the Netbox API and ensures Credential work properly - + .DESCRIPTION Connects to the Netbox API and ensures Credential work properly - + .PARAMETER Hostname The hostname for the resource such as netbox.domain.com - + .PARAMETER Credential Credential object containing the API key in the password. Username is not applicable - + .PARAMETER Scheme Scheme for the URI such as HTTP or HTTPS. Defaults to HTTPS - + .PARAMETER Port Port for the resource. Value between 1-65535 - + .PARAMETER URI The full URI for the resource such as "https://netbox.domain.com:8443" - + + .PARAMETER SkipCertificateCheck + A description of the SkipCertificateCheck parameter. + + .PARAMETER TimeoutSeconds + The number of seconds before the HTTP call times out. Defaults to 30 seconds + .EXAMPLE PS C:\> Connect-NetboxAPI -Hostname "netbox.domain.com" - + This will prompt for Credential, then proceed to attempt a connection to Netbox - + .NOTES Additional information about the function. #> - + [CmdletBinding(DefaultParameterSetName = 'Manual')] param ( [Parameter(ParameterSetName = 'Manual', Mandatory = $true)] [string]$Hostname, - + [Parameter(Mandatory = $false)] [pscredential]$Credential, - + [Parameter(ParameterSetName = 'Manual')] [ValidateSet('https', 'http', IgnoreCase = $true)] [string]$Scheme = 'https', - + [Parameter(ParameterSetName = 'Manual')] [uint16]$Port = 443, - + [Parameter(ParameterSetName = 'URI', Mandatory = $true)] - [string]$URI + [string]$URI, + + [Parameter(Mandatory = $false)] + [switch]$SkipCertificateCheck = $false, + + [ValidateNotNullOrEmpty()] + [ValidateRange(1, 65535)] + [uint16]$TimeoutSeconds = 30 ) - + if (-not $Credential) { try { $Credential = Get-NetboxCredential -ErrorAction Stop @@ -531,14 +544,29 @@ function Connect-NetboxAPI { } } } - - $null = Set-NetboxCredential -Credential $Credential - + + $invokeParams = @{ SkipCertificateCheck = $SkipCertificateCheck; } + + if ("Desktop" -eq $PSVersionTable.PsEdition) { + #Remove -SkipCertificateCheck from Invoke Parameter (not supported <= PS 5) + $invokeParams.remove("SkipCertificateCheck") + } + + #for PowerShell (<=) 5 (Desktop), Enable TLS 1.1, 1.2 and Disable SSL chain trust + if ("Desktop" -eq $PSVersionTable.PsEdition) { + #Enable TLS 1.1 and 1.2 + Set-NetboxCipherSSL + if ($SkipCertificateCheck) { + #Disable SSL chain trust... + Set-NetboxuntrustedSSL + } + } + switch ($PSCmdlet.ParameterSetName) { 'Manual' { $uriBuilder = [System.UriBuilder]::new($Scheme, $Hostname, $Port) } - + 'URI' { $uriBuilder = [System.UriBuilder]::new($URI) if ([string]::IsNullOrWhiteSpace($uriBuilder.Host)) { @@ -546,11 +574,14 @@ function Connect-NetboxAPI { } } } - + $null = Set-NetboxHostName -Hostname $uriBuilder.Host + $null = Set-NetboxCredential -Credential $Credential $null = Set-NetboxHostScheme -Scheme $uriBuilder.Scheme $null = Set-NetboxHostPort -Port $uriBuilder.Port - + $null = Set-NetboxInvokeParams -invokeParams $invokeParams + $null = Set-NetboxTimeout -TimeoutSeconds $TimeoutSeconds + try { Write-Verbose "Verifying API connectivity..." $null = VerifyAPIConnectivity @@ -563,18 +594,27 @@ function Connect-NetboxAPI { throw $_ } } - - Write-Verbose "Caching API definition" - $script:NetboxConfig.APIDefinition = Get-NetboxAPIDefinition - - if ([version]$script:NetboxConfig.APIDefinition.info.version -lt 2.8) { + +# Write-Verbose "Caching API definition" +# $script:NetboxConfig.APIDefinition = Get-NetboxAPIDefinition +# +# if ([version]$script:NetboxConfig.APIDefinition.info.version -lt 2.8) { +# $Script:NetboxConfig.Connected = $false +# throw "Netbox version is incompatible with this PS module. Requires >=2.8.*, found version $($script:NetboxConfig.APIDefinition.info.version)" + # } + + Write-Verbose "Checking Netbox version compatibility" + $script:NetboxConfig.NetboxVersion = Get-NetboxVersion + if ([version]$script:NetboxConfig.NetboxVersion.'netbox-version' -lt 2.8) { $Script:NetboxConfig.Connected = $false - throw "Netbox version is incompatible with this PS module. Requires >=2.8.*, found version $($script:NetboxConfig.APIDefinition.info.version)" + throw "Netbox version is incompatible with this PS module. Requires >=2.8.*, found version $($script:NetboxConfig.NetboxVersion.'netbox-version')" + } else { + Write-Verbose "Found compatible version [$($script:NetboxConfig.NetboxVersion.'netbox-version')]!" } - + $script:NetboxConfig.Connected = $true Write-Verbose "Successfully connected!" - + #Write-Verbose "Caching static choices" #$script:NetboxConfig.Choices.Circuits = Get-NetboxCircuitsChoices #$script:NetboxConfig.Choices.DCIM = Get-NetboxDCIMChoices # Not completed yet @@ -583,7 +623,7 @@ function Connect-NetboxAPI { ##$script:NetboxConfig.Choices.Secrets = Get-NetboxSecretsChoices # Not completed yet ##$script:NetboxConfig.Choices.Tenancy = Get-NetboxTenancyChoices #$script:NetboxConfig.Choices.Virtualization = Get-NetboxVirtualizationChoices - + Write-Verbose "Connection process completed" } @@ -706,17 +746,17 @@ function Get-ModelDefinition { #region File Get-NetboxAPIDefinition.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.174 - Created on: 4/28/2020 11:57 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxAPIDefinition.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. +<# + .NOTES + =========================================================================== + Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.174 + Created on: 4/28/2020 11:57 + Created by: Claussen + Organization: NEOnet + Filename: Get-NetboxAPIDefinition.ps1 + =========================================================================== + .DESCRIPTION + A description of the file. #> @@ -724,16 +764,16 @@ function Get-ModelDefinition { function Get-NetboxAPIDefinition { [CmdletBinding()] param () - + #$URI = "https://netbox.neonet.org/api/docs/?format=openapi" - + $Segments = [System.Collections.ArrayList]::new(@('docs')) - - $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary @{'format' = 'openapi'} - + + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary @{'format' = 'openapi' } + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters -SkipConnectedCheck - - InvokeNetboxRequest -URI $URI -Timeout 10 + + InvokeNetboxRequest -URI $URI } #endregion @@ -1152,11 +1192,11 @@ function Get-NetboxCredential { [CmdletBinding()] [OutputType([pscredential])] param () - + if (-not $script:NetboxConfig.Credential) { throw "Netbox Credentials not set! You may set with Set-NetboxCredential" } - + $script:NetboxConfig.Credential } @@ -1702,12 +1742,12 @@ function Get-NetboxDCIMSite { function Get-NetboxHostname { [CmdletBinding()] param () - + Write-Verbose "Getting Netbox hostname" if ($null -eq $script:NetboxConfig.Hostname) { throw "Netbox Hostname is not set! You may set it with Set-NetboxHostname -Hostname 'hostname.domain.tld'" } - + $script:NetboxConfig.Hostname } @@ -1745,6 +1785,22 @@ function Get-NetboxHostScheme { #endregion +#region File Get-NetboxInvokeParams.ps1 + +function Get-NetboxInvokeParams { + [CmdletBinding()] + param () + + Write-Verbose "Getting Netbox InvokeParams" + if ($null -eq $script:NetboxConfig.InvokeParams) { + throw "Netbox Invoke Params is not set! You may set it with Set-NetboxInvokeParams -InvokeParams ..." + } + + $script:NetboxConfig.InvokeParams +} + +#endregion + #region File Get-NetboxIPAMAddress.ps1 function Get-NetboxIPAMAddress { @@ -2553,6 +2609,44 @@ function Get-NetboxTenant { #endregion +#region File Get-NetboxTimeout.ps1 + + +function Get-NetboxTimeout { + [CmdletBinding()] + [OutputType([uint16])] + param () + + Write-Verbose "Getting Netbox Timeout" + if ($null -eq $script:NetboxConfig.Timeout) { + throw "Netbox Timeout is not set! You may set it with Set-NetboxTimeout -TimeoutSeconds [uint16]" + } + + $script:NetboxConfig.Timeout +} + +#endregion + +#region File Get-NetboxVersion.ps1 + + +function Get-NetboxVersion { + [CmdletBinding()] + param () + + $Segments = [System.Collections.ArrayList]::new(@('status')) + + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary @{ + 'format' = 'json' + } + + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters -SkipConnectedCheck + + InvokeNetboxRequest -URI $URI +} + +#endregion + #region File Get-NetboxVirtualizationCluster.ps1 <# @@ -2969,7 +3063,7 @@ function Get-NetboxVirtualMachineInterface { #region File InvokeNetboxRequest.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -2989,44 +3083,46 @@ function InvokeNetboxRequest { ( [Parameter(Mandatory = $true)] [System.UriBuilder]$URI, - + [Hashtable]$Headers = @{ }, - + [pscustomobject]$Body = $null, - - [ValidateRange(0, 60)] - [uint16]$Timeout = 5, - + + [ValidateRange(1, 65535)] + [uint16]$Timeout = (Get-NetboxTimeout), + [ValidateSet('GET', 'PATCH', 'PUT', 'POST', 'DELETE', 'OPTIONS', IgnoreCase = $true)] [string]$Method = 'GET', - + [switch]$Raw ) - + $creds = Get-NetboxCredential - + $Headers.Authorization = "Token {0}" -f $creds.GetNetworkCredential().Password - + $splat = @{ - 'Method' = $Method - 'Uri' = $URI.Uri.AbsoluteUri # This property auto generates the scheme, hostname, path, and query - 'Headers' = $Headers - 'TimeoutSec' = $Timeout + 'Method' = $Method + 'Uri' = $URI.Uri.AbsoluteUri # This property auto generates the scheme, hostname, path, and query + 'Headers' = $Headers + 'TimeoutSec' = $Timeout 'ContentType' = 'application/json' 'ErrorAction' = 'Stop' - 'Verbose' = $VerbosePreference + 'Verbose' = $VerbosePreference } - + + $splat += Get-NetboxInvokeParams + if ($Body) { Write-Verbose "BODY: $($Body | ConvertTo-Json -Compress)" $null = $splat.Add('Body', ($Body | ConvertTo-Json -Compress)) } - + $result = Invoke-RestMethod @splat - + #region TODO: Handle errors a little more gracefully... - + <# try { Write-Verbose "Sending request..." @@ -3040,7 +3136,7 @@ function InvokeNetboxRequest { Write-Verbose "RAW provided...throwing raw exception" throw $_ } - + Write-Verbose "Converting response to object" $myError = GetNetboxAPIErrorBody -Response $_.Exception.Response | ConvertFrom-Json } else { @@ -3048,18 +3144,18 @@ function InvokeNetboxRequest { $myError = $_ } } - + Write-Verbose "MyError is $($myError.GetType().FullName)" - + if ($myError -is [Exception]) { throw $_ } elseif ($myError -is [pscustomobject]) { throw $myError.detail - } + } #> - + #endregion TODO: Handle errors a little more gracefully... - + # If the user wants the raw value from the API... otherwise return only the actual result if ($Raw) { Write-Verbose "Returning raw result by choice" @@ -3936,37 +4032,50 @@ function Remove-NetboxVirtualMachine { #endregion +#region File Set-NetboxCipherSSL.ps1 + +Function Set-NetboxCipherSSL { + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessforStateChangingFunctions", "")] + Param( ) + # Hack for allowing TLS 1.1 and TLS 1.2 (by default it is only SSL3 and TLS (1.0)) + $AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12' + [System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols + +} + +#endregion + #region File Set-NetboxCredential.ps1 function Set-NetboxCredential { [CmdletBinding(DefaultParameterSetName = 'CredsObject', - ConfirmImpact = 'Low', - SupportsShouldProcess = $true)] + ConfirmImpact = 'Low', + SupportsShouldProcess = $true)] [OutputType([pscredential])] param ( [Parameter(ParameterSetName = 'CredsObject', - Mandatory = $true)] + Mandatory = $true)] [pscredential]$Credential, - + [Parameter(ParameterSetName = 'UserPass', - Mandatory = $true)] + Mandatory = $true)] [securestring]$Token ) - + if ($PSCmdlet.ShouldProcess('Netbox Credentials', 'Set')) { switch ($PsCmdlet.ParameterSetName) { 'CredsObject' { $script:NetboxConfig.Credential = $Credential break } - + 'UserPass' { $script:NetboxConfig.Credential = [System.Management.Automation.PSCredential]::new('notapplicable', $Token) break } } - + $script:NetboxConfig.Credential } } @@ -4277,14 +4386,14 @@ function Set-NetboxDCIMInterfaceConnection { function Set-NetboxHostName { [CmdletBinding(ConfirmImpact = 'Low', - SupportsShouldProcess = $true)] + SupportsShouldProcess = $true)] [OutputType([string])] param ( [Parameter(Mandatory = $true)] [string]$Hostname ) - + if ($PSCmdlet.ShouldProcess('Netbox Hostname', 'Set')) { $script:NetboxConfig.Hostname = $Hostname.Trim() $script:NetboxConfig.Hostname @@ -4338,6 +4447,25 @@ function Set-NetboxHostScheme { #endregion +#region File Set-NetboxInvokeParams.ps1 + +function Set-NetboxInvokeParams { + [CmdletBinding(ConfirmImpact = 'Low', + SupportsShouldProcess = $true)] + [OutputType([string])] + param( + [Parameter(Mandatory = $true)] + [array]$InvokeParams + ) + + if ($PSCmdlet.ShouldProcess('Netbox Invoke Params', 'Set')) { + $script:NetboxConfig.InvokeParams = $InvokeParams + $script:NetboxConfig.InvokeParams + } +} + +#endregion + #region File Set-NetboxIPAMAddress.ps1 <# @@ -4534,6 +4662,52 @@ function Set-NetboxIPAMPrefix { +#endregion + +#region File Set-NetboxTimeout.ps1 + + +function Set-NetboxTimeout { + [CmdletBinding(ConfirmImpact = 'Low', + SupportsShouldProcess = $true)] + [OutputType([uint16])] + param + ( + [Parameter(Mandatory = $false)] + [ValidateRange(1, 65535)] + [uint16]$TimeoutSeconds = 30 + ) + + if ($PSCmdlet.ShouldProcess('Netbox Timeout', 'Set')) { + $script:NetboxConfig.Timeout = $TimeoutSeconds + $script:NetboxConfig.Timeout + } +} + +#endregion + +#region File Set-NetboxUnstrustedSSL.ps1 + +Function Set-NetboxUntrustedSSL { + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessforStateChangingFunctions", "")] + Param( ) + # Hack for allowing untrusted SSL certs with https connections + Add-Type -TypeDefinition @" + using System.Net; + using System.Security.Cryptography.X509Certificates; + public class TrustAllCertsPolicy : ICertificatePolicy { + public bool CheckValidationResult( + ServicePoint srvPoint, X509Certificate certificate, + WebRequest request, int certificateProblem) { + return true; + } + } +"@ + + [System.Net.ServicePointManager]::CertificatePolicy = New-Object -TypeName TrustAllCertsPolicy + +} + #endregion #region File Set-NetboxVirtualMachine.ps1 @@ -4691,18 +4865,18 @@ function SetupNetboxConfigVariable { ( [switch]$Overwrite ) - + Write-Verbose "Checking for NetboxConfig hashtable" if ((-not ($script:NetboxConfig)) -or $Overwrite) { Write-Verbose "Creating NetboxConfig hashtable" $script:NetboxConfig = @{ - 'Connected' = $false - 'Choices' = @{ + 'Connected' = $false + 'Choices' = @{ } 'APIDefinition' = $null } } - + Write-Verbose "NetboxConfig hashtable already exists" } @@ -4783,11 +4957,11 @@ function ThrowNetboxRESTError { function VerifyAPIConnectivity { [CmdletBinding()] param () - + $uriSegments = [System.Collections.ArrayList]::new(@('extras')) - - $uri = BuildNewURI -Segments $uriSegments -Parameters @{'format' = 'json'} -SkipConnectedCheck - + + $uri = BuildNewURI -Segments $uriSegments -Parameters @{'format' = 'json' } -SkipConnectedCheck + InvokeNetboxRequest -URI $uri } From 01335bd225a7c2bdc4b6b403ff34926aa1e71b34 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Fri, 23 Jul 2021 16:24:27 +0200 Subject: [PATCH 21/68] Fix Typo and Enhance AvailableIP Example (#18) * AvailableIP(IPAM/Address): Fix typo * AvailableIP(IAPM/Address): Enhance Example * NetboxPS(.psm1): Fix typo (paramters => parameters --- Functions/IPAM/Address/Get-NetboxIPAMAvailableIP.ps1 | 9 ++++++++- NetboxPS.psm1 | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Functions/IPAM/Address/Get-NetboxIPAMAvailableIP.ps1 b/Functions/IPAM/Address/Get-NetboxIPAMAvailableIP.ps1 index 4d77712..e026cb8 100644 --- a/Functions/IPAM/Address/Get-NetboxIPAMAvailableIP.ps1 +++ b/Functions/IPAM/Address/Get-NetboxIPAMAvailableIP.ps1 @@ -34,7 +34,14 @@ function Get-NetboxIPAMAvailableIP { A description of the NumberOfIPs parameter. .EXAMPLE - PS C:\> Get-NetboxIPAMAvaiableIP -Prefix_ID $value1 + Get-NetboxIPAMAvailableIP -Prefix_ID (Get-NetboxIPAMPrefix -Prefix 192.0.2.0/24).id + + Get (Next) Available IP on the Prefix 192.0.2.0/24 + + .EXAMPLE + Get-NetboxIPAMAvailableIP -Prefix_ID 2 -NumberOfIPs 3 + + Get 3 (Next) Available IP on the Prefix 192.0.2.0/24 .NOTES Additional information about the function. diff --git a/NetboxPS.psm1 b/NetboxPS.psm1 index cc051fc..6d66fc6 100644 --- a/NetboxPS.psm1 +++ b/NetboxPS.psm1 @@ -10,7 +10,7 @@ Script generated by PowerShell Studio 2020 #> -# Build a list of common paramters so we can omit them to build URI parameters +# Build a list of common parameters so we can omit them to build URI parameters $script:CommonParameterNames = New-Object System.Collections.ArrayList [void]$script:CommonParameterNames.AddRange(@([System.Management.Automation.PSCmdlet]::CommonParameters)) [void]$script:CommonParameterNames.AddRange(@([System.Management.Automation.PSCmdlet]::OptionalCommonParameters)) From 11ae767a6c2dc9c9cc24da4ea6c42e5ab3cad72b Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Fri, 23 Jul 2021 10:26:14 -0400 Subject: [PATCH 22/68] Update deployment files --- NetboxPS.psd1 | 4 ++-- NetboxPS/NetboxPS.psd1 | 4 ++-- NetboxPS/NetboxPS.psm1 | 11 +++++++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/NetboxPS.psd1 b/NetboxPS.psd1 index ead3b18..a6b4a3f 100644 --- a/NetboxPS.psd1 +++ b/NetboxPS.psd1 @@ -3,7 +3,7 @@ # # Generated by: Ben Claussen # -# Generated on: 2021-07-22 +# Generated on: 2021-07-23 # @{ @@ -12,7 +12,7 @@ RootModule = 'NetboxPS.psm1' # Version number of this module. -ModuleVersion = '1.4' +ModuleVersion = '1.4.1' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/NetboxPS/NetboxPS.psd1 b/NetboxPS/NetboxPS.psd1 index ead3b18..a6b4a3f 100644 --- a/NetboxPS/NetboxPS.psd1 +++ b/NetboxPS/NetboxPS.psd1 @@ -3,7 +3,7 @@ # # Generated by: Ben Claussen # -# Generated on: 2021-07-22 +# Generated on: 2021-07-23 # @{ @@ -12,7 +12,7 @@ RootModule = 'NetboxPS.psm1' # Version number of this module. -ModuleVersion = '1.4' +ModuleVersion = '1.4.1' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/NetboxPS/NetboxPS.psm1 b/NetboxPS/NetboxPS.psm1 index 61fa4b8..1b31bb1 100644 --- a/NetboxPS/NetboxPS.psm1 +++ b/NetboxPS/NetboxPS.psm1 @@ -2021,7 +2021,14 @@ function Get-NetboxIPAMAvailableIP { A description of the NumberOfIPs parameter. .EXAMPLE - PS C:\> Get-NetboxIPAMAvaiableIP -Prefix_ID $value1 + Get-NetboxIPAMAvailableIP -Prefix_ID (Get-NetboxIPAMPrefix -Prefix 192.0.2.0/24).id + + Get (Next) Available IP on the Prefix 192.0.2.0/24 + + .EXAMPLE + Get-NetboxIPAMAvailableIP -Prefix_ID 2 -NumberOfIPs 3 + + Get 3 (Next) Available IP on the Prefix 192.0.2.0/24 .NOTES Additional information about the function. @@ -4979,7 +4986,7 @@ function VerifyAPIConnectivity { Script generated by PowerShell Studio 2020 #> -# Build a list of common paramters so we can omit them to build URI parameters +# Build a list of common parameters so we can omit them to build URI parameters $script:CommonParameterNames = New-Object System.Collections.ArrayList [void]$script:CommonParameterNames.AddRange(@([System.Management.Automation.PSCmdlet]::CommonParameters)) [void]$script:CommonParameterNames.AddRange(@([System.Management.Automation.PSCmdlet]::OptionalCommonParameters)) From ddf1d22e18910d08b79699885131f38be8dce84b Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Fri, 23 Jul 2021 22:03:07 +0200 Subject: [PATCH 23/68] Add Assigned Object (Type and ID) to New IPAM Address (#19) * IPAMAddress(New): Remove tab (use 4 spaces) * IPAMAddress(New): Remove not longer needed code about value validation * IPAMAddress(New): Add Assigned Object Type and ID Fix #17 * IPAMAddress(New): add Parameter example * IPAMAddress(New): Add Validate for Assigned Object Type Can be only dcim.interface or virtualization.vminterface * IPAMAddress(New): Fix Example (it is New and not Create Verb !) * IPAMAddress(New): Remove -Force parameter, use -Confirm if you want a confirmation it is the standard with ShouldProcess --- .../IPAM/Address/New-NetboxIPAMAddress.ps1 | 49 +++++++++---------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/Functions/IPAM/Address/New-NetboxIPAMAddress.ps1 b/Functions/IPAM/Address/New-NetboxIPAMAddress.ps1 index 736ef99..8650d9a 100644 --- a/Functions/IPAM/Address/New-NetboxIPAMAddress.ps1 +++ b/Functions/IPAM/Address/New-NetboxIPAMAddress.ps1 @@ -1,14 +1,14 @@ <# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 11:51 - Created by: Claussen - Organization: NEOnet - Filename: New-NetboxIPAMAddress.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. + .NOTES + =========================================================================== + Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 + Created on: 3/19/2020 11:51 + Created by: Claussen + Organization: NEOnet + Filename: New-NetboxIPAMAddress.ps1 + =========================================================================== + .DESCRIPTION + A description of the file. #> @@ -50,14 +50,19 @@ function New-NetboxIPAMAddress { .PARAMETER Dns_name DNS Name of IP address (example : netbox.example.com) - .PARAMETER Force - Do not prompt for confirmation to create IP. + .PARAMETER Assigned_Object_Type + Assigned Object Type dcim.interface or virtualization.vminterface + + .PARAMETER Assigned_Object_Id + Assigned Object ID .PARAMETER Raw Return raw results from API service .EXAMPLE - PS C:\> Create-NetboxIPAMAddress + New-NetboxIPAMAddress -Address 192.0.2.1/32 + + Add new IP Address 192.0.2.1/32 with status active .NOTES Additional information about the function. @@ -90,7 +95,10 @@ function New-NetboxIPAMAddress { [string]$Dns_name, - [switch]$Force, + [ValidateSet('dcim.interface', 'virtualization.vminterface', IgnoreCase = $true)] + [string]$Assigned_Object_Type, + + [int]$Assigned_Object_Id, [switch]$Raw ) @@ -99,22 +107,11 @@ function New-NetboxIPAMAddress { $Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses')) $Method = 'POST' - # # Value validation - # $ModelDefinition = GetModelDefinitionFromURIPath -Segments $Segments -Method $Method - # $EnumProperties = GetModelEnumProperties -ModelDefinition $ModelDefinition - # - # foreach ($Property in $EnumProperties.Keys) { - # if ($PSBoundParameters.ContainsKey($Property)) { - # Write-Verbose "Validating property [$Property] with value [$($PSBoundParameters.$Property)]" - # $PSBoundParameters.$Property = ValidateValue -ModelDefinition $ModelDefinition -Property $Property -ProvidedValue $PSBoundParameters.$Property - # } - # } - # $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters $URI = BuildNewURI -Segments $URIComponents.Segments - if ($Force -or $PSCmdlet.ShouldProcess($Address, 'Create new IP address')) { + if ($PSCmdlet.ShouldProcess($Address, 'Create new IP address')) { InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw } } From 8167b0dbf037df217a090d983379a5d0b898b185 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Fri, 23 Jul 2021 22:06:42 +0200 Subject: [PATCH 24/68] Fix PSSA Warning (#20) * Fix trailing white space using Invoke-ScriptAnalyzer -Fix -Path . -Recurse * add settings.json for configure Visual Code (Formatter) * PSSA: Fix Command accepts pipeline input but has not defined a process block * PSSA: Fix PSUseDeclaredVarsMoreThanAssignments The variable 'I_B' is assigned but never used The variable 'I_A' is assigned but never used * PSSA: Fix PSUseShouldProcessForStateChangingFunctions Function New-/Set-... has verb that could change system state. Therefore, the function has to support 'ShouldProcess' --- .vscode/settings.json | 10 + Functions/Circuits/Circuits.ps1 | 2 +- .../Circuits/Circuits/Get-NetboxCircuit.ps1 | 100 +- .../Circuits/Circuits/New-NetboxCircuit.ps1 | 54 +- .../Providers/Get-NetboxCircuitProvider.ps1 | 34 +- .../Get-NetboxCircuitTermination.ps1 | 38 +- .../Circuits/Types/Get-NetboxCircuitType.ps1 | 30 +- .../DCIM/Devices/Get-NetboxDCIMDevice.ps1 | 90 +- .../DCIM/Devices/Get-NetboxDCIMDeviceRole.ps1 | 34 +- .../DCIM/Devices/Get-NetboxDCIMDeviceType.ps1 | 40 +- .../DCIM/Devices/New-NetboxDCIMDevice.ps1 | 87 +- .../DCIM/Devices/Remove-NetboxDCIMDevice.ps1 | 32 +- .../DCIM/Devices/Set-NetboxDCIMDevice.ps1 | 62 +- Functions/DCIM/Get-NetboxDCIMPlatform.ps1 | 34 +- .../Interfaces/Add-NetboxDCIMInterface.ps1 | 42 +- .../Add-NetboxDCIMInterfaceConnection.ps1 | 38 +- .../Interfaces/Get-NetboxDCIMInterface.ps1 | 52 +- .../Get-NetboxDCIMInterfaceConnection.ps1 | 24 +- .../Interfaces/Remove-NetboxDCIMInterface.ps1 | 32 +- .../Remove-NetboxDCIMInterfaceConnection.ps1 | 22 +- .../Interfaces/Set-NetboxDCIMInterface.ps1 | 65 +- .../Set-NetboxDCIMInterfaceConnection.ps1 | 48 +- Functions/DCIM/Sites/Get-NetboxDCIMSite.ps1 | 82 +- Functions/Helpers/BuildNewURI.ps1 | 44 +- Functions/Helpers/BuildURIComponents.ps1 | 28 +- Functions/Helpers/CheckNetboxIsConnected.ps1 | 4 +- Functions/Helpers/CreateEnum.ps1 | 8 +- Functions/Helpers/Get-ModelDefinition.ps1 | 22 +- Functions/Helpers/GetNetboxAPIErrorBody.ps1 | 6 +- Functions/Helpers/ThrowNetboxRESTError.ps1 | 8 +- .../Aggregate/Get-NetboxIPAMAggregate.ps1 | 40 +- .../IPAM/Prefix/Get-NetboxIPAMPrefix.ps1 | 122 +- .../IPAM/Prefix/New-NetboxIPAMPrefix.ps1 | 42 +- .../IPAM/Prefix/Set-NetboxIPAMPrefix.ps1 | 42 +- Functions/IPAM/Role/Get-NetboxIPAMRole.ps1 | 58 +- Functions/IPAM/VLAN/Get-NetboxIPAMVLAN.ps1 | 60 +- Functions/IPAM/VLAN/New-NetboxIPAMVLAN.ps1 | 69 +- Functions/Setup/Get-NetboxHostPort.ps1 | 4 +- Functions/Setup/Get-NetboxHostScheme.ps1 | 4 +- Functions/Setup/Set-NetboxHostPort.ps1 | 2 +- Functions/Setup/Set-NetboxHostScheme.ps1 | 4 +- Functions/Tenancy/Get-NetboxTenant.ps1 | 68 +- Functions/Tenancy/Tenancy.ps1 | 2 +- .../Get-NetboxVirtualMachine.ps1 | 120 +- .../New-NetboxVirtualMachine.ps1 | 57 +- .../Remove-NetboxVirtualMachine.ps1 | 32 +- .../Set-NetboxVirtualMachine.ps1 | 74 +- .../Add-NetboxVirtualMachineInterface.ps1 | 24 +- .../Get-NetboxVirtualMachineInterface.ps1 | 70 +- .../Set-NetboxVirtualMachineInterface.ps1 | 34 +- .../Get-NetboxVirtualizationCluster.ps1 | 64 +- .../Get-NetboxVirtualizationClusterGroup.ps1 | 24 +- NetboxPS/NetboxPS.psm1 | 1934 ++++++++--------- Tests/DCIM.Devices.Tests.ps1 | 234 +- Tests/DCIM.Interfaces.Tests.ps1 | 204 +- Tests/DCIM.Platforms.Tests.ps1 | 44 +- Tests/Helpers.Tests.ps1 | 320 +-- Tests/IPAM.Tests.ps1 | 260 +-- Tests/Setup.Tests.ps1 | 32 +- Tests/Virtualization.Tests.ps1 | 262 +-- deploy.ps1 | 38 +- 61 files changed, 2779 insertions(+), 2737 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..cc82cf9 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,10 @@ +// Place your settings in this file to overwrite default and user settings. +{ + "editor.formatOnSave": true, + "files.trimTrailingWhitespace": true, + "powershell.scriptAnalysis.settingsPath": ".vscode/PSScriptAnalyzerSettings.psd1", + "powershell.codeFormatting.newLineAfterCloseBrace": false, + "[markdown]": { + "files.trimTrailingWhitespace": false, + } +} \ No newline at end of file diff --git a/Functions/Circuits/Circuits.ps1 b/Functions/Circuits/Circuits.ps1 index 967548f..6b2af57 100644 --- a/Functions/Circuits/Circuits.ps1 +++ b/Functions/Circuits/Circuits.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.148 diff --git a/Functions/Circuits/Circuits/Get-NetboxCircuit.ps1 b/Functions/Circuits/Circuits/Get-NetboxCircuit.ps1 index 319ee48..34b2ced 100644 --- a/Functions/Circuits/Circuits/Get-NetboxCircuit.ps1 +++ b/Functions/Circuits/Circuits/Get-NetboxCircuit.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -13,119 +13,121 @@ function Get-NetboxCircuit { -<# + <# .SYNOPSIS Gets one or more circuits - + .DESCRIPTION A detailed description of the Get-NetboxCircuit function. - + .PARAMETER Id Database ID of circuit. This will query for exactly the IDs provided - + .PARAMETER CID Circuit ID - + .PARAMETER InstallDate Date of installation - + .PARAMETER CommitRate Committed rate in Kbps - + .PARAMETER Query A raw search query... As if you were searching the web site - + .PARAMETER Provider The name or ID of the provider. Provide either [string] or [int]. String will search provider names, integer will search database IDs - + .PARAMETER Type Type of circuit. Provide either [string] or [int]. String will search provider type names, integer will search database IDs - + .PARAMETER Site Location/site of circuit. Provide either [string] or [int]. String will search site names, integer will search database IDs - + .PARAMETER Tenant Tenant assigned to circuit. Provide either [string] or [int]. String will search tenant names, integer will search database IDs - + .PARAMETER Limit A description of the Limit parameter. - + .PARAMETER Offset A description of the Offset parameter. - + .PARAMETER Raw A description of the Raw parameter. - + .PARAMETER ID__IN Multiple unique DB IDs to retrieve - + .EXAMPLE PS C:\> Get-NetboxCircuit - + .NOTES Additional information about the function. #> - + [CmdletBinding(DefaultParameterSetName = 'Query')] param ( [Parameter(ParameterSetName = 'ById')] [uint16[]]$Id, - + [Parameter(ParameterSetName = 'Query')] [string]$CID, - + [Parameter(ParameterSetName = 'Query')] [datetime]$InstallDate, - + [Parameter(ParameterSetName = 'Query')] [uint32]$CommitRate, - + [Parameter(ParameterSetName = 'Query')] [string]$Query, - + [Parameter(ParameterSetName = 'Query')] [object]$Provider, - + [Parameter(ParameterSetName = 'Query')] [object]$Type, - + [Parameter(ParameterSetName = 'Query')] [string]$Site, - + [Parameter(ParameterSetName = 'Query')] [string]$Tenant, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Limit, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Offset, - + [switch]$Raw ) - - switch ($PSCmdlet.ParameterSetName) { - 'ById' { - foreach ($i in $ID) { - $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits', $i)) - - $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id" - + + process { + switch ($PSCmdlet.ParameterSetName) { + 'ById' { + foreach ($i in $ID) { + $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits', $i)) + + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id" + + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters + + InvokeNetboxRequest -URI $URI -Raw:$Raw + } + } + + default { + $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits')) + + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } } - - default { - $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits')) - - $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters - - $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - - InvokeNetboxRequest -URI $URI -Raw:$Raw - } } } \ No newline at end of file diff --git a/Functions/Circuits/Circuits/New-NetboxCircuit.ps1 b/Functions/Circuits/Circuits/New-NetboxCircuit.ps1 index aac3447..650a006 100644 --- a/Functions/Circuits/Circuits/New-NetboxCircuit.ps1 +++ b/Functions/Circuits/Circuits/New-NetboxCircuit.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 @@ -15,53 +15,55 @@ function New-NetboxCircuit { [CmdletBinding(ConfirmImpact = 'Low', - SupportsShouldProcess = $true)] + SupportsShouldProcess = $true)] [OutputType([pscustomobject])] param ( [Parameter(Mandatory = $true, - ValueFromPipelineByPropertyName = $true)] + ValueFromPipelineByPropertyName = $true)] [string]$CID, - + [Parameter(Mandatory = $true)] [uint32]$Provider, - + [Parameter(Mandatory = $true)] [uint32]$Type, - + #[ValidateSet('Active', 'Planned', 'Provisioning', 'Offline', 'Deprovisioning', 'Decommissioned ')] [uint16]$Status = 'Active', - + [string]$Description, - + [uint32]$Tenant, - + [string]$Termination_A, - + [datetime]$Install_Date, - + [string]$Termination_Z, - + [ValidateRange(0, 2147483647)] [uint32]$Commit_Rate, - + [string]$Comments, - + [hashtable]$Custom_Fields, - + [switch]$Force, - + [switch]$Raw ) - - $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits')) - $Method = 'POST' - - $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - - $URI = BuildNewURI -Segments $URIComponents.Segments - - if ($Force -or $PSCmdlet.ShouldProcess($CID, 'Create new circuit')) { - InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw + + process { + $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits')) + $Method = 'POST' + + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters + + $URI = BuildNewURI -Segments $URIComponents.Segments + + if ($Force -or $PSCmdlet.ShouldProcess($CID, 'Create new circuit')) { + InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw + } } } \ No newline at end of file diff --git a/Functions/Circuits/Providers/Get-NetboxCircuitProvider.ps1 b/Functions/Circuits/Providers/Get-NetboxCircuitProvider.ps1 index 07ad3ca..8e392e0 100644 --- a/Functions/Circuits/Providers/Get-NetboxCircuitProvider.ps1 +++ b/Functions/Circuits/Providers/Get-NetboxCircuitProvider.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 @@ -20,52 +20,52 @@ function Get-NetboxCircuitProvider { [Parameter(ParameterSetName = 'ById', Mandatory = $true)] [uint16[]]$Id, - + [Parameter(ParameterSetName = 'Query', Mandatory = $false)] [string]$Name, - + [Parameter(ParameterSetName = 'Query')] [string]$Query, - + [Parameter(ParameterSetName = 'Query')] [string]$Slug, - + [Parameter(ParameterSetName = 'Query')] [string]$ASN, - + [Parameter(ParameterSetName = 'Query')] [string]$Account, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Limit, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Offset, - + [switch]$Raw ) - + switch ($PSCmdlet.ParameterSetName) { 'ById' { foreach ($i in $ID) { $Segments = [System.Collections.ArrayList]::new(@('circuits', 'providers', $i)) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id" - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } } - + default { $Segments = [System.Collections.ArrayList]::new(@('circuits', 'providers')) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } } diff --git a/Functions/Circuits/Terminations/Get-NetboxCircuitTermination.ps1 b/Functions/Circuits/Terminations/Get-NetboxCircuitTermination.ps1 index 6e055fd..930c244 100644 --- a/Functions/Circuits/Terminations/Get-NetboxCircuitTermination.ps1 +++ b/Functions/Circuits/Terminations/Get-NetboxCircuitTermination.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 @@ -20,58 +20,58 @@ function Get-NetboxCircuitTermination { [Parameter(ParameterSetName = 'ById', ValueFromPipelineByPropertyName = $true)] [uint32[]]$Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Circuit_ID, - + [Parameter(ParameterSetName = 'Query')] [string]$Term_Side, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Port_Speed, - + [Parameter(ParameterSetName = 'Query')] [string]$Query, - + [Parameter(ParameterSetName = 'Query')] [string]$Site_ID, - + [Parameter(ParameterSetName = 'Query')] [string]$Site, - + [Parameter(ParameterSetName = 'Query')] [string]$XConnect_ID, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Limit, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Offset, - + [switch]$Raw ) - + process { switch ($PSCmdlet.ParameterSetName) { 'ById' { foreach ($i in $ID) { $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuit-terminations', $i)) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id" - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } } - + default { $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuit-terminations')) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } } diff --git a/Functions/Circuits/Types/Get-NetboxCircuitType.ps1 b/Functions/Circuits/Types/Get-NetboxCircuitType.ps1 index bce6ad5..16cd88e 100644 --- a/Functions/Circuits/Types/Get-NetboxCircuitType.ps1 +++ b/Functions/Circuits/Types/Get-NetboxCircuitType.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 @@ -19,45 +19,45 @@ function Get-NetboxCircuitType { ( [Parameter(ParameterSetName = 'ById')] [uint16[]]$Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Name, - + [Parameter(ParameterSetName = 'Query')] [string]$Slug, - + [Parameter(ParameterSetName = 'Query')] [string]$Query, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Limit, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Offset, - + [switch]$Raw ) - + switch ($PSCmdlet.ParameterSetName) { 'ById' { foreach ($i in $ID) { $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuit_types', $i)) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id" - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } } - + default { $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuit-types')) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } } diff --git a/Functions/DCIM/Devices/Get-NetboxDCIMDevice.ps1 b/Functions/DCIM/Devices/Get-NetboxDCIMDevice.ps1 index a14c1cc..ff7237c 100644 --- a/Functions/DCIM/Devices/Get-NetboxDCIMDevice.ps1 +++ b/Functions/DCIM/Devices/Get-NetboxDCIMDevice.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -18,82 +18,84 @@ function Get-NetboxDCIMDevice { param ( [uint16]$Limit, - + [uint16]$Offset, - + [Parameter(ValueFromPipelineByPropertyName = $true)] [uint16[]]$Id, - + [string]$Query, - + [string]$Name, - + [uint16]$Manufacturer_Id, - + [string]$Manufacturer, - + [uint16]$Device_Type_Id, - + [uint16]$Role_Id, - + [string]$Role, - + [uint16]$Tenant_Id, - + [string]$Tenant, - + [uint16]$Platform_Id, - + [string]$Platform, - + [string]$Asset_Tag, - + [uint16]$Site_Id, - + [string]$Site, - + [uint16]$Rack_Group_Id, - + [uint16]$Rack_Id, - + [uint16]$Cluster_Id, - + [uint16]$Model, - + [object]$Status, - + [bool]$Is_Full_Depth, - + [bool]$Is_Console_Server, - + [bool]$Is_PDU, - + [bool]$Is_Network_Device, - + [string]$MAC_Address, - + [bool]$Has_Primary_IP, - + [uint16]$Virtual_Chassis_Id, - + [uint16]$Position, - + [string]$Serial, - + [switch]$Raw ) - + #endregion Parameters - - if ($null -ne $Status) { - $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus + + process { + if ($null -ne $Status) { + $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus + } + + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices')) + + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw' + + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters + + InvokeNetboxRequest -URI $URI -Raw:$Raw } - - $Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices')) - - $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw' - - $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - - InvokeNetboxRequest -URI $URI -Raw:$Raw } \ No newline at end of file diff --git a/Functions/DCIM/Devices/Get-NetboxDCIMDeviceRole.ps1 b/Functions/DCIM/Devices/Get-NetboxDCIMDeviceRole.ps1 index 3ca2974..afcad80 100644 --- a/Functions/DCIM/Devices/Get-NetboxDCIMDeviceRole.ps1 +++ b/Functions/DCIM/Devices/Get-NetboxDCIMDeviceRole.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -17,45 +17,45 @@ function Get-NetboxDCIMDeviceRole { param ( [uint16]$Limit, - + [uint16]$Offset, - + [Parameter(ParameterSetName = 'ById')] [uint16[]]$Id, - + [string]$Name, - + [string]$Slug, - + [string]$Color, - + [bool]$VM_Role, - + [switch]$Raw ) - + switch ($PSCmdlet.ParameterSetName) { 'ById' { foreach ($DRId in $Id) { $Segments = [System.Collections.ArrayList]::new(@('dcim', 'device-roles', $DRId)) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Raw' - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } - + break } - + default { $Segments = [System.Collections.ArrayList]::new(@('dcim', 'device-roles')) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw' - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } } diff --git a/Functions/DCIM/Devices/Get-NetboxDCIMDeviceType.ps1 b/Functions/DCIM/Devices/Get-NetboxDCIMDeviceType.ps1 index ffba0e2..5bd55b8 100644 --- a/Functions/DCIM/Devices/Get-NetboxDCIMDeviceType.ps1 +++ b/Functions/DCIM/Devices/Get-NetboxDCIMDeviceType.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -18,44 +18,44 @@ function Get-NetboxDCIMDeviceType { param ( [uint16]$Offset, - + [uint16]$Limit, - + [uint16[]]$Id, - + [string]$Query, - + [string]$Slug, - + [string]$Manufacturer, - + [uint16]$Manufacturer_Id, - + [string]$Model, - + [string]$Part_Number, - + [uint16]$U_Height, - + [bool]$Is_Full_Depth, - + [bool]$Is_Console_Server, - + [bool]$Is_PDU, - + [bool]$Is_Network_Device, - + [uint16]$Subdevice_Role, - + [switch]$Raw ) #endregion Parameters - + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'device-types')) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw' - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } \ No newline at end of file diff --git a/Functions/DCIM/Devices/New-NetboxDCIMDevice.ps1 b/Functions/DCIM/Devices/New-NetboxDCIMDevice.ps1 index 3a6751d..b99e237 100644 --- a/Functions/DCIM/Devices/New-NetboxDCIMDevice.ps1 +++ b/Functions/DCIM/Devices/New-NetboxDCIMDevice.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -13,78 +13,81 @@ function New-NetboxDCIMDevice { - [CmdletBinding()] + [CmdletBinding(ConfirmImpact = 'low', + SupportsShouldProcess = $true)] [OutputType([pscustomobject])] #region Parameters param ( [Parameter(Mandatory = $true)] [string]$Name, - + [Parameter(Mandatory = $true)] [object]$Device_Role, - + [Parameter(Mandatory = $true)] [object]$Device_Type, - + [Parameter(Mandatory = $true)] [uint16]$Site, - + [object]$Status = 'Active', - + [uint16]$Platform, - + [uint16]$Tenant, - + [uint16]$Cluster, - + [uint16]$Rack, - + [uint16]$Position, - + [object]$Face, - + [string]$Serial, - + [string]$Asset_Tag, - + [uint16]$Virtual_Chassis, - + [uint16]$VC_Priority, - + [uint16]$VC_Position, - + [uint16]$Primary_IP4, - + [uint16]$Primary_IP6, - + [string]$Comments, - + [hashtable]$Custom_Fields ) #endregion Parameters - -# if ($null -ne $Device_Role) { -# # Validate device role? -# } -# -# if ($null -ne $Device_Type) { -# # Validate device type? -# } -# -# if ($null -ne $Status) { -# $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus -# } -# -# if ($null -ne $Face) { -# $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace -# } - + + # if ($null -ne $Device_Role) { + # # Validate device role? + # } + + # if ($null -ne $Device_Type) { + # # Validate device type? + # } + + # if ($null -ne $Status) { + # $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus + # } + + # if ($null -ne $Face) { + # $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace + # } + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices')) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters - + $URI = BuildNewURI -Segments $URIComponents.Segments - - InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST + + if ($PSCmdlet.ShouldProcess($Name, 'Create new Device')) { + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST + } } \ No newline at end of file diff --git a/Functions/DCIM/Devices/Remove-NetboxDCIMDevice.ps1 b/Functions/DCIM/Devices/Remove-NetboxDCIMDevice.ps1 index e654b9e..747f959 100644 --- a/Functions/DCIM/Devices/Remove-NetboxDCIMDevice.ps1 +++ b/Functions/DCIM/Devices/Remove-NetboxDCIMDevice.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -16,23 +16,23 @@ function Remove-NetboxDCIMDevice { <# .SYNOPSIS Delete a device - + .DESCRIPTION Deletes a device from Netbox by ID - + .PARAMETER Id Database ID of the device - + .PARAMETER Force Force deletion without any prompts - + .EXAMPLE PS C:\> Remove-NetboxDCIMDevice -Id $value1 - + .NOTES Additional information about the function. #> - + [CmdletBinding(ConfirmImpact = 'High', SupportsShouldProcess = $true)] param @@ -40,29 +40,29 @@ function Remove-NetboxDCIMDevice { [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [uint16[]]$Id, - + [switch]$Force ) - + begin { - + } - + process { foreach ($DeviceID in $Id) { $CurrentDevice = Get-NetboxDCIMDevice -Id $DeviceID -ErrorAction Stop - + if ($Force -or $pscmdlet.ShouldProcess("Name: $($CurrentDevice.Name) | ID: $($CurrentDevice.Id)", "Remove")) { $Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices', $CurrentDevice.Id)) - + $URI = BuildNewURI -Segments $Segments - + InvokeNetboxRequest -URI $URI -Method DELETE } } } - + end { - + } } \ No newline at end of file diff --git a/Functions/DCIM/Devices/Set-NetboxDCIMDevice.ps1 b/Functions/DCIM/Devices/Set-NetboxDCIMDevice.ps1 index 00b50fc..3bfac65 100644 --- a/Functions/DCIM/Devices/Set-NetboxDCIMDevice.ps1 +++ b/Functions/DCIM/Devices/Set-NetboxDCIMDevice.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -19,77 +19,77 @@ function Set-NetboxDCIMDevice { [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [uint16[]]$Id, - + [string]$Name, - + [object]$Device_Role, - + [object]$Device_Type, - + [uint16]$Site, - + [object]$Status, - + [uint16]$Platform, - + [uint16]$Tenant, - + [uint16]$Cluster, - + [uint16]$Rack, - + [uint16]$Position, - + [object]$Face, - + [string]$Serial, - + [string]$Asset_Tag, - + [uint16]$Virtual_Chassis, - + [uint16]$VC_Priority, - + [uint16]$VC_Position, - + [uint16]$Primary_IP4, - + [uint16]$Primary_IP6, - + [string]$Comments, - + [hashtable]$Custom_Fields, - + [switch]$Force ) - + begin { # if ($null -ne $Status) { # $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus # } -# + # if ($null -ne $Face) { # $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace # } } - + process { foreach ($DeviceID in $Id) { $CurrentDevice = Get-NetboxDCIMDevice -Id $DeviceID -ErrorAction Stop - + if ($Force -or $pscmdlet.ShouldProcess("$($CurrentDevice.Name)", "Set")) { $Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices', $CurrentDevice.Id)) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force' - + $URI = BuildNewURI -Segments $URIComponents.Segments - + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH } } } - + end { - + } } diff --git a/Functions/DCIM/Get-NetboxDCIMPlatform.ps1 b/Functions/DCIM/Get-NetboxDCIMPlatform.ps1 index 4ae982f..d2bd323 100644 --- a/Functions/DCIM/Get-NetboxDCIMPlatform.ps1 +++ b/Functions/DCIM/Get-NetboxDCIMPlatform.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -18,45 +18,45 @@ function Get-NetboxDCIMPlatform { param ( [uint16]$Limit, - + [uint16]$Offset, - + [Parameter(ParameterSetName = 'ById')] [uint16[]]$Id, - + [string]$Name, - + [string]$Slug, - + [uint16]$Manufacturer_Id, - + [string]$Manufacturer, - + [switch]$Raw ) - + switch ($PSCmdlet.ParameterSetName) { 'ById' { foreach ($PlatformID in $Id) { $Segments = [System.Collections.ArrayList]::new(@('dcim', 'platforms', $PlatformID)) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Raw' - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } - + break } - + default { $Segments = [System.Collections.ArrayList]::new(@('dcim', 'platforms')) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw' - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } } diff --git a/Functions/DCIM/Interfaces/Add-NetboxDCIMInterface.ps1 b/Functions/DCIM/Interfaces/Add-NetboxDCIMInterface.ps1 index c792d35..75a5f29 100644 --- a/Functions/DCIM/Interfaces/Add-NetboxDCIMInterface.ps1 +++ b/Functions/DCIM/Interfaces/Add-NetboxDCIMInterface.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -19,66 +19,66 @@ function Add-NetboxDCIMInterface { ( [Parameter(Mandatory = $true)] [uint16]$Device, - + [Parameter(Mandatory = $true)] [string]$Name, - + [bool]$Enabled, - + [object]$Form_Factor, - + [uint16]$MTU, - + [string]$MAC_Address, - + [bool]$MGMT_Only, - + [uint16]$LAG, - + [string]$Description, - + [ValidateSet('Access', 'Tagged', 'Tagged All', '100', '200', '300', IgnoreCase = $true)] [string]$Mode, - + [ValidateRange(1, 4094)] [uint16]$Untagged_VLAN, - + [ValidateRange(1, 4094)] [uint16[]]$Tagged_VLANs ) - + # if ($null -ne $Form_Factor) { # $PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor # } - + if (-not [System.String]::IsNullOrWhiteSpace($Mode)) { $PSBoundParameters.Mode = switch ($Mode) { 'Access' { 100 break } - + 'Tagged' { 200 break } - + 'Tagged All' { 300 break } - + default { $_ } } } - + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces')) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters - + $URI = BuildNewURI -Segments $URIComponents.Segments - + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST } \ No newline at end of file diff --git a/Functions/DCIM/Interfaces/Add-NetboxDCIMInterfaceConnection.ps1 b/Functions/DCIM/Interfaces/Add-NetboxDCIMInterfaceConnection.ps1 index f98c2e3..d848b0c 100644 --- a/Functions/DCIM/Interfaces/Add-NetboxDCIMInterfaceConnection.ps1 +++ b/Functions/DCIM/Interfaces/Add-NetboxDCIMInterfaceConnection.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -13,55 +13,55 @@ function Add-NetboxDCIMInterfaceConnection { -<# + <# .SYNOPSIS Create a new connection between two interfaces - + .DESCRIPTION Create a new connection between two interfaces - + .PARAMETER Connection_Status Is it connected or planned? - + .PARAMETER Interface_A Database ID of interface A - + .PARAMETER Interface_B Database ID of interface B - + .EXAMPLE PS C:\> Add-NetboxDCIMInterfaceConnection -Interface_A $value1 -Interface_B $value2 - + .NOTES Additional information about the function. #> - + [CmdletBinding()] [OutputType([pscustomobject])] param ( [object]$Connection_Status, - + [Parameter(Mandatory = $true)] [uint16]$Interface_A, - + [Parameter(Mandatory = $true)] [uint16]$Interface_B ) - + if ($null -ne $Connection_Status) { $PSBoundParameters.Connection_Status = ValidateDCIMChoice -ProvidedValue $Connection_Status -InterfaceConnectionStatus } - + # Verify if both Interfaces exist - $I_A = Get-NetboxDCIMInterface -Id $Interface_A -ErrorAction Stop - $I_B = Get-NetboxDCIMInterface -Id $Interface_B -ErrorAction Stop - + Get-NetboxDCIMInterface -Id $Interface_A -ErrorAction Stop | Out-null + Get-NetboxDCIMInterface -Id $Interface_B -ErrorAction Stop | Out-null + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections')) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters - + $URI = BuildNewURI -Segments $URIComponents.Segments - + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST } \ No newline at end of file diff --git a/Functions/DCIM/Interfaces/Get-NetboxDCIMInterface.ps1 b/Functions/DCIM/Interfaces/Get-NetboxDCIMInterface.ps1 index 671f013..f0c64f7 100644 --- a/Functions/DCIM/Interfaces/Get-NetboxDCIMInterface.ps1 +++ b/Functions/DCIM/Interfaces/Get-NetboxDCIMInterface.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -18,44 +18,46 @@ function Get-NetboxDCIMInterface { param ( [uint16]$Limit, - + [uint16]$Offset, - + [Parameter(ValueFromPipelineByPropertyName = $true)] [uint16]$Id, - + [uint16]$Name, - + [object]$Form_Factor, - + [bool]$Enabled, - + [uint16]$MTU, - + [bool]$MGMT_Only, - + [string]$Device, - + [uint16]$Device_Id, - + [uint16]$Type, - + [uint16]$LAG_Id, - + [string]$MAC_Address, - + [switch]$Raw ) - - if ($null -ne $Form_Factor) { - $PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor + + process { + if ($null -ne $Form_Factor) { + $PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor + } + + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces')) + + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters + + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters + + InvokeNetboxRequest -URI $URI -Raw:$Raw } - - $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces')) - - $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters - - $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - - InvokeNetboxRequest -URI $URI -Raw:$Raw } \ No newline at end of file diff --git a/Functions/DCIM/Interfaces/Get-NetboxDCIMInterfaceConnection.ps1 b/Functions/DCIM/Interfaces/Get-NetboxDCIMInterfaceConnection.ps1 index f3fe97d..9c4ca22 100644 --- a/Functions/DCIM/Interfaces/Get-NetboxDCIMInterfaceConnection.ps1 +++ b/Functions/DCIM/Interfaces/Get-NetboxDCIMInterfaceConnection.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -18,29 +18,29 @@ function Get-NetboxDCIMInterfaceConnection { param ( [uint16]$Limit, - + [uint16]$Offset, - + [uint16]$Id, - + [object]$Connection_Status, - + [uint16]$Site, - + [uint16]$Device, - + [switch]$Raw ) - + if ($null -ne $Connection_Status) { $PSBoundParameters.Connection_Status = ValidateDCIMChoice -ProvidedValue $Connection_Status -InterfaceConnectionStatus } - + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections')) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw' - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } \ No newline at end of file diff --git a/Functions/DCIM/Interfaces/Remove-NetboxDCIMInterface.ps1 b/Functions/DCIM/Interfaces/Remove-NetboxDCIMInterface.ps1 index 1996a1c..2e73c2b 100644 --- a/Functions/DCIM/Interfaces/Remove-NetboxDCIMInterface.ps1 +++ b/Functions/DCIM/Interfaces/Remove-NetboxDCIMInterface.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -16,23 +16,23 @@ function Remove-NetboxDCIMInterface { <# .SYNOPSIS Removes an interface - + .DESCRIPTION Removes an interface by ID from a device - + .PARAMETER Id A description of the Id parameter. - + .PARAMETER Force A description of the Force parameter. - + .EXAMPLE PS C:\> Remove-NetboxDCIMInterface -Id $value1 - + .NOTES Additional information about the function. #> - + [CmdletBinding(ConfirmImpact = 'High', SupportsShouldProcess = $true)] param @@ -40,29 +40,29 @@ function Remove-NetboxDCIMInterface { [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [uint16[]]$Id, - + [switch]$Force ) - + begin { - + } - + process { foreach ($InterfaceId in $Id) { $CurrentInterface = Get-NetboxDCIMInterface -Id $InterfaceId -ErrorAction Stop - + if ($Force -or $pscmdlet.ShouldProcess("Name: $($CurrentInterface.Name) | ID: $($CurrentInterface.Id)", "Remove")) { $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces', $CurrentInterface.Id)) - + $URI = BuildNewURI -Segments $Segments - + InvokeNetboxRequest -URI $URI -Method DELETE } } } - + end { - + } } \ No newline at end of file diff --git a/Functions/DCIM/Interfaces/Remove-NetboxDCIMInterfaceConnection.ps1 b/Functions/DCIM/Interfaces/Remove-NetboxDCIMInterfaceConnection.ps1 index 52e13dc..d7dc205 100644 --- a/Functions/DCIM/Interfaces/Remove-NetboxDCIMInterfaceConnection.ps1 +++ b/Functions/DCIM/Interfaces/Remove-NetboxDCIMInterfaceConnection.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -21,31 +21,31 @@ function Remove-NetboxDCIMInterfaceConnection { [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [uint16[]]$Id, - + [switch]$Force ) - + begin { - + } - + process { foreach ($ConnectionID in $Id) { $CurrentConnection = Get-NetboxDCIMInterfaceConnection -Id $ConnectionID -ErrorAction Stop - + if ($Force -or $pscmdlet.ShouldProcess("Connection ID $($ConnectionID.Id)", "REMOVE")) { $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections', $CurrentConnection.Id)) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force' - + $URI = BuildNewURI -Segments $URIComponents.Segments - + InvokeNetboxRequest -URI $URI -Method DELETE } } } - + end { - + } } \ No newline at end of file diff --git a/Functions/DCIM/Interfaces/Set-NetboxDCIMInterface.ps1 b/Functions/DCIM/Interfaces/Set-NetboxDCIMInterface.ps1 index 431065a..d08ecd6 100644 --- a/Functions/DCIM/Interfaces/Set-NetboxDCIMInterface.ps1 +++ b/Functions/DCIM/Interfaces/Set-NetboxDCIMInterface.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -13,86 +13,89 @@ function Set-NetboxDCIMInterface { - [CmdletBinding()] + [CmdletBinding(ConfirmImpact = 'Medium', + SupportsShouldProcess = $true)] [OutputType([pscustomobject])] param ( [Parameter(Mandatory = $true, - ValueFromPipelineByPropertyName = $true)] + ValueFromPipelineByPropertyName = $true)] [uint16[]]$Id, - + [uint16]$Device, - + [string]$Name, - + [bool]$Enabled, - + [object]$Form_Factor, - + [uint16]$MTU, - + [string]$MAC_Address, - + [bool]$MGMT_Only, - + [uint16]$LAG, - + [string]$Description, - + [ValidateSet('Access', 'Tagged', 'Tagged All', '100', '200', '300', IgnoreCase = $true)] [string]$Mode, - + [ValidateRange(1, 4094)] [uint16]$Untagged_VLAN, - + [ValidateRange(1, 4094)] [uint16[]]$Tagged_VLANs ) - + begin { -# if ($null -ne $Form_Factor) { -# $PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor -# } - + # if ($null -ne $Form_Factor) { + # $PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor + # } + if (-not [System.String]::IsNullOrWhiteSpace($Mode)) { $PSBoundParameters.Mode = switch ($Mode) { 'Access' { 100 break } - + 'Tagged' { 200 break } - + 'Tagged All' { 300 break } - + default { $_ } } } } - + process { foreach ($InterfaceId in $Id) { $CurrentInterface = Get-NetboxDCIMInterface -Id $InterfaceId -ErrorAction Stop - + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces', $CurrentInterface.Id)) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id' - + $URI = BuildNewURI -Segments $Segments - - InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH + + if ($Force -or $pscmdlet.ShouldProcess("Interface ID $($CurrentInterface.Id)", "Set")) { + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH + } } } - + end { - + } } \ No newline at end of file diff --git a/Functions/DCIM/Interfaces/Set-NetboxDCIMInterfaceConnection.ps1 b/Functions/DCIM/Interfaces/Set-NetboxDCIMInterfaceConnection.ps1 index 0836bfc..abe84aa 100644 --- a/Functions/DCIM/Interfaces/Set-NetboxDCIMInterfaceConnection.ps1 +++ b/Functions/DCIM/Interfaces/Set-NetboxDCIMInterfaceConnection.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -16,32 +16,32 @@ function Set-NetboxDCIMInterfaceConnection { <# .SYNOPSIS Update an interface connection - + .DESCRIPTION Update an interface connection - + .PARAMETER Id A description of the Id parameter. - + .PARAMETER Connection_Status A description of the Connection_Status parameter. - + .PARAMETER Interface_A A description of the Interface_A parameter. - + .PARAMETER Interface_B A description of the Interface_B parameter. - + .PARAMETER Force A description of the Force parameter. - + .EXAMPLE PS C:\> Set-NetboxDCIMInterfaceConnection -Id $value1 - + .NOTES Additional information about the function. #> - + [CmdletBinding(ConfirmImpact = 'Medium', SupportsShouldProcess = $true)] param @@ -49,44 +49,44 @@ function Set-NetboxDCIMInterfaceConnection { [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [uint16[]]$Id, - + [object]$Connection_Status, - + [uint16]$Interface_A, - + [uint16]$Interface_B, - + [switch]$Force ) - + begin { # if ($null -ne $Connection_Status) { # $PSBoundParameters.Connection_Status = ValidateDCIMChoice -ProvidedValue $Connection_Status -InterfaceConnectionStatus # } - + if ((@($ID).Count -gt 1) -and ($Interface_A -or $Interface_B)) { throw "Cannot set multiple connections to the same interface" } } - + process { foreach ($ConnectionID in $Id) { $CurrentConnection = Get-NetboxDCIMInterfaceConnection -Id $ConnectionID -ErrorAction Stop - + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections', $CurrentConnection.Id)) - + if ($Force -or $pscmdlet.ShouldProcess("Connection ID $($CurrentConnection.Id)", "Set")) { - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force' - + $URI = BuildNewURI -Segments $URIComponents.Segments - + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH } } } - + end { - + } } \ No newline at end of file diff --git a/Functions/DCIM/Sites/Get-NetboxDCIMSite.ps1 b/Functions/DCIM/Sites/Get-NetboxDCIMSite.ps1 index b7e13a4..90c6e2a 100644 --- a/Functions/DCIM/Sites/Get-NetboxDCIMSite.ps1 +++ b/Functions/DCIM/Sites/Get-NetboxDCIMSite.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 @@ -20,89 +20,91 @@ function Get-NetboxDCIMSite { ( [Parameter(ParameterSetName = 'ByID', ValueFromPipelineByPropertyName = $true)] [uint32]$Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Name, - + [Parameter(ParameterSetName = 'Query')] [string]$Query, - + [Parameter(ParameterSetName = 'Query')] [string]$Slug, - + [Parameter(ParameterSetName = 'Query')] [string]$Facility, - + [Parameter(ParameterSetName = 'Query')] [uint32]$ASN, - + [Parameter(ParameterSetName = 'Query')] [decimal]$Latitude, - + [Parameter(ParameterSetName = 'Query')] [decimal]$Longitude, - + [Parameter(ParameterSetName = 'Query')] [string]$Contact_Name, - + [Parameter(ParameterSetName = 'Query')] [string]$Contact_Phone, - + [Parameter(ParameterSetName = 'Query')] [string]$Contact_Email, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Tenant_Group_ID, - + [Parameter(ParameterSetName = 'Query')] [string]$Tenant_Group, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Tenant_ID, - + [Parameter(ParameterSetName = 'Query')] [string]$Tenant, - + [Parameter(ParameterSetName = 'Query')] [string]$Status, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Region_ID, - + [Parameter(ParameterSetName = 'Query')] [string]$Region, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Limit, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Offset, - + [switch]$Raw ) - - switch ($PSCmdlet.ParameterSetName) { - 'ById' { - foreach ($Site_ID in $ID) { - $Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites', $Site_Id)) - - $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id" - + + process { + switch ($PSCmdlet.ParameterSetName) { + 'ById' { + foreach ($Site_ID in $ID) { + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites', $Site_Id)) + + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id" + + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters + + InvokeNetboxRequest -URI $URI -Raw:$Raw + } + } + + default { + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites')) + + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } } - - default { - $Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites')) - - $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters - - $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - - InvokeNetboxRequest -URI $URI -Raw:$Raw - } } } diff --git a/Functions/Helpers/BuildNewURI.ps1 b/Functions/Helpers/BuildNewURI.ps1 index 842b25b..700f339 100644 --- a/Functions/Helpers/BuildNewURI.ps1 +++ b/Functions/Helpers/BuildNewURI.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -16,77 +16,77 @@ function BuildNewURI { <# .SYNOPSIS Create a new URI for Netbox - + .DESCRIPTION Internal function used to build a URIBuilder object. - + .PARAMETER Hostname Hostname of the Netbox API - + .PARAMETER Segments Array of strings for each segment in the URL path - + .PARAMETER Parameters Hashtable of query parameters to include - + .PARAMETER HTTPS Whether to use HTTPS or HTTP - + .PARAMETER Port A description of the Port parameter. - + .PARAMETER APIInfo A description of the APIInfo parameter. - + .EXAMPLE PS C:\> BuildNewURI - + .NOTES Additional information about the function. #> - + [CmdletBinding()] [OutputType([System.UriBuilder])] param ( [Parameter(Mandatory = $false)] [string[]]$Segments, - + [Parameter(Mandatory = $false)] [hashtable]$Parameters, - + [switch]$SkipConnectedCheck ) - + Write-Verbose "Building URI" - + if (-not $SkipConnectedCheck) { # There is no point in continuing if we have not successfully connected to an API $null = CheckNetboxIsConnected } - + # Begin a URI builder with HTTP/HTTPS and the provided hostname $uriBuilder = [System.UriBuilder]::new($script:NetboxConfig.HostScheme, $script:NetboxConfig.Hostname, $script:NetboxConfig.HostPort) - + # Generate the path by trimming excess slashes and whitespace from the $segments[] and joining together $uriBuilder.Path = "api/{0}/" -f ($Segments.ForEach({ $_.trim('/').trim() }) -join '/') - + Write-Verbose " URIPath: $($uriBuilder.Path)" - + if ($parameters) { # Loop through the parameters and use the HttpUtility to create a Query string [System.Collections.Specialized.NameValueCollection]$URIParams = [System.Web.HttpUtility]::ParseQueryString([String]::Empty) - + foreach ($param in $Parameters.GetEnumerator()) { Write-Verbose " Adding URI parameter $($param.Key):$($param.Value)" $URIParams[$param.Key] = $param.Value } - + $uriBuilder.Query = $URIParams.ToString() } - + Write-Verbose " Completed building URIBuilder" # Return the entire UriBuilder object $uriBuilder diff --git a/Functions/Helpers/BuildURIComponents.ps1 b/Functions/Helpers/BuildURIComponents.ps1 index 495f3f9..d9f60a8 100644 --- a/Functions/Helpers/BuildURIComponents.ps1 +++ b/Functions/Helpers/BuildURIComponents.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -19,30 +19,30 @@ function BuildURIComponents { ( [Parameter(Mandatory = $true)] [System.Collections.ArrayList]$URISegments, - + [Parameter(Mandatory = $true)] [object]$ParametersDictionary, - + [string[]]$SkipParameterByName ) - + Write-Verbose "Building URI components" - + $URIParameters = @{ } - + foreach ($CmdletParameterName in $ParametersDictionary.Keys) { if ($CmdletParameterName -in $script:CommonParameterNames) { # These are common parameters and should not be appended to the URI Write-Debug "Skipping common parameter $CmdletParameterName" continue } - + if ($CmdletParameterName -in $SkipParameterByName) { Write-Debug "Skipping parameter $CmdletParameterName by SkipParameterByName" continue } - + switch ($CmdletParameterName) { "id" { # Check if there is one or more values for Id and build a URI or query as appropriate @@ -53,26 +53,26 @@ function BuildURIComponents { Write-Verbose " Adding ID to segments" [void]$uriSegments.Add($ParametersDictionary[$CmdletParameterName]) } - + break } - + 'Query' { Write-Verbose " Adding query parameter" $URIParameters['q'] = $ParametersDictionary[$CmdletParameterName] break } - + 'CustomFields' { Write-Verbose " Adding custom field query parameters" foreach ($field in $ParametersDictionary[$CmdletParameterName].GetEnumerator()) { Write-Verbose " Adding parameter 'cf_$($field.Key) = $($field.Value)" $URIParameters["cf_$($field.Key.ToLower())"] = $field.Value } - + break } - + default { Write-Verbose " Adding $($CmdletParameterName.ToLower()) parameter" $URIParameters[$CmdletParameterName.ToLower()] = $ParametersDictionary[$CmdletParameterName] @@ -80,7 +80,7 @@ function BuildURIComponents { } } } - + return @{ 'Segments' = [System.Collections.ArrayList]$URISegments 'Parameters' = $URIParameters diff --git a/Functions/Helpers/CheckNetboxIsConnected.ps1 b/Functions/Helpers/CheckNetboxIsConnected.ps1 index 045fe37..aca5057 100644 --- a/Functions/Helpers/CheckNetboxIsConnected.ps1 +++ b/Functions/Helpers/CheckNetboxIsConnected.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -15,7 +15,7 @@ function CheckNetboxIsConnected { [CmdletBinding()] param () - + Write-Verbose "Checking connection status" if (-not $script:NetboxConfig.Connected) { throw "Not connected to a Netbox API! Please run 'Connect-NetboxAPI'" diff --git a/Functions/Helpers/CreateEnum.ps1 b/Functions/Helpers/CreateEnum.ps1 index 7903899..89fe25a 100644 --- a/Functions/Helpers/CreateEnum.ps1 +++ b/Functions/Helpers/CreateEnum.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -18,13 +18,13 @@ function CreateEnum { ( [Parameter(Mandatory = $true)] [string]$EnumName, - + [Parameter(Mandatory = $true)] [pscustomobject]$Values, - + [switch]$PassThru ) - + $definition = @" public enum $EnumName {`n$(foreach ($value in $values) { diff --git a/Functions/Helpers/Get-ModelDefinition.ps1 b/Functions/Helpers/Get-ModelDefinition.ps1 index bf389fa..c8969c9 100644 --- a/Functions/Helpers/Get-ModelDefinition.ps1 +++ b/Functions/Helpers/Get-ModelDefinition.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 @@ -20,45 +20,45 @@ function Get-ModelDefinition { [Parameter(ParameterSetName = 'ByName', Mandatory = $true)] [string]$ModelName, - + [Parameter(ParameterSetName = 'ByPath', Mandatory = $true)] [string]$URIPath, - + [Parameter(ParameterSetName = 'ByPath')] [string]$Method = "post" ) - + switch ($PsCmdlet.ParameterSetName) { 'ByName' { $script:NetboxConfig.APIDefinition.definitions.$ModelName break } - + 'ByPath' { switch ($Method) { "get" { - + break } - + "post" { if (-not $URIPath.StartsWith('/')) { $URIPath = "/$URIPath" } - + if (-not $URIPath.EndsWith('/')) { $URIPath = "$URIPath/" } - + $ModelName = $script:NetboxConfig.APIDefinition.paths.$URIPath.post.parameters.schema.'$ref'.split('/')[-1] $script:NetboxConfig.APIDefinition.definitions.$ModelName break } } - + break } } - + } diff --git a/Functions/Helpers/GetNetboxAPIErrorBody.ps1 b/Functions/Helpers/GetNetboxAPIErrorBody.ps1 index 6dca60b..96bd3fe 100644 --- a/Functions/Helpers/GetNetboxAPIErrorBody.ps1 +++ b/Functions/Helpers/GetNetboxAPIErrorBody.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -18,10 +18,10 @@ function GetNetboxAPIErrorBody { [Parameter(Mandatory = $true)] [System.Net.HttpWebResponse]$Response ) - + # This takes the $Response stream and turns it into a useable object... generally a string. # If the body is JSON, you should be able to use ConvertFrom-Json - + $reader = New-Object System.IO.StreamReader($Response.GetResponseStream()) $reader.BaseStream.Position = 0 $reader.DiscardBufferedData() diff --git a/Functions/Helpers/ThrowNetboxRESTError.ps1 b/Functions/Helpers/ThrowNetboxRESTError.ps1 index 69d4cfd..078de90 100644 --- a/Functions/Helpers/ThrowNetboxRESTError.ps1 +++ b/Functions/Helpers/ThrowNetboxRESTError.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -14,11 +14,11 @@ function ThrowNetboxRESTError { $uriSegments = [System.Collections.ArrayList]::new(@('fake', 'url')) - + $URIParameters = @{ } - + $uri = BuildNewURI -Segments $uriSegments -Parameters $URIParameters - + InvokeNetboxRequest -URI $uri -Raw } \ No newline at end of file diff --git a/Functions/IPAM/Aggregate/Get-NetboxIPAMAggregate.ps1 b/Functions/IPAM/Aggregate/Get-NetboxIPAMAggregate.ps1 index a696bc6..87e82da 100644 --- a/Functions/IPAM/Aggregate/Get-NetboxIPAMAggregate.ps1 +++ b/Functions/IPAM/Aggregate/Get-NetboxIPAMAggregate.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -18,61 +18,61 @@ function Get-NetboxIPAMAggregate { ( [Parameter(ParameterSetName = 'Query')] [string]$Query, - + [Parameter(ParameterSetName = 'ByID')] [uint16[]]$Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Prefix, - + [Parameter(ParameterSetName = 'Query')] [object]$Family, - + [Parameter(ParameterSetName = 'Query')] [uint16]$RIR_Id, - + [Parameter(ParameterSetName = 'Query')] [string]$RIR, - + [Parameter(ParameterSetName = 'Query')] [datetime]$Date_Added, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Limit, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Offset, - + [switch]$Raw ) - + # if ($null -ne $Family) { # $PSBoundParameters.Family = ValidateIPAMChoice -ProvidedValue $Family -AggregateFamily # } - + switch ($PSCmdlet.ParameterSetName) { 'ById' { foreach ($IP_ID in $Id) { $Segments = [System.Collections.ArrayList]::new(@('ipam', 'aggregates', $IP_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(@('ipam', 'aggregates')) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $uri -Raw:$Raw - + break } } diff --git a/Functions/IPAM/Prefix/Get-NetboxIPAMPrefix.ps1 b/Functions/IPAM/Prefix/Get-NetboxIPAMPrefix.ps1 index a554fb6..11a5fd0 100644 --- a/Functions/IPAM/Prefix/Get-NetboxIPAMPrefix.ps1 +++ b/Functions/IPAM/Prefix/Get-NetboxIPAMPrefix.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -16,189 +16,189 @@ function Get-NetboxIPAMPrefix { <# .SYNOPSIS A brief description of the Get-NetboxIPAMPrefix function. - + .DESCRIPTION A detailed description of the Get-NetboxIPAMPrefix function. - + .PARAMETER Query A description of the Query parameter. - + .PARAMETER Id A description of the Id parameter. - + .PARAMETER Limit A description of the Limit parameter. - + .PARAMETER Offset A description of the Offset parameter. - + .PARAMETER Family A description of the Family parameter. - + .PARAMETER Is_Pool A description of the Is_Pool parameter. - + .PARAMETER Within Should be a CIDR notation prefix such as '10.0.0.0/16' - + .PARAMETER Within_Include Should be a CIDR notation prefix such as '10.0.0.0/16' - + .PARAMETER Contains A description of the Contains parameter. - + .PARAMETER Mask_Length CIDR mask length value - + .PARAMETER VRF A description of the VRF parameter. - + .PARAMETER VRF_Id A description of the VRF_Id parameter. - + .PARAMETER Tenant A description of the Tenant parameter. - + .PARAMETER Tenant_Id A description of the Tenant_Id parameter. - + .PARAMETER Site A description of the Site parameter. - + .PARAMETER Site_Id A description of the Site_Id parameter. - + .PARAMETER Vlan_VId A description of the Vlan_VId parameter. - + .PARAMETER Vlan_Id A description of the Vlan_Id parameter. - + .PARAMETER Status A description of the Status parameter. - + .PARAMETER Role A description of the Role parameter. - + .PARAMETER Role_Id A description of the Role_Id parameter. - + .PARAMETER Raw A description of the Raw parameter. - + .EXAMPLE PS C:\> Get-NetboxIPAMPrefix - + .NOTES Additional information about the function. #> - + [CmdletBinding(DefaultParameterSetName = 'Query')] param ( [Parameter(ParameterSetName = 'Query', Position = 0)] [string]$Prefix, - + [Parameter(ParameterSetName = 'Query')] [string]$Query, - + [Parameter(ParameterSetName = 'ByID')] [uint32[]]$Id, - + [Parameter(ParameterSetName = 'Query')] [object]$Family, - + [Parameter(ParameterSetName = 'Query')] [boolean]$Is_Pool, - + [Parameter(ParameterSetName = 'Query')] [string]$Within, - + [Parameter(ParameterSetName = 'Query')] [string]$Within_Include, - + [Parameter(ParameterSetName = 'Query')] [string]$Contains, - + [Parameter(ParameterSetName = 'Query')] [ValidateRange(0, 127)] [byte]$Mask_Length, - + [Parameter(ParameterSetName = 'Query')] [string]$VRF, - + [Parameter(ParameterSetName = 'Query')] [uint32]$VRF_Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Tenant, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Tenant_Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Site, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Site_Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Vlan_VId, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Vlan_Id, - + [Parameter(ParameterSetName = 'Query')] [object]$Status, - + [Parameter(ParameterSetName = 'Query')] [string]$Role, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Role_Id, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Limit, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Offset, - + [switch]$Raw ) - + # if ($null -ne $Family) { # $PSBoundParameters.Family = ValidateIPAMChoice -ProvidedValue $Family -PrefixFamily # } - # + # # if ($null -ne $Status) { # $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -PrefixStatus # } - + switch ($PSCmdlet.ParameterSetName) { 'ById' { foreach ($Prefix_ID in $Id) { $Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes', $Prefix_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(@('ipam', 'prefixes')) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $uri -Raw:$Raw - + break } } diff --git a/Functions/IPAM/Prefix/New-NetboxIPAMPrefix.ps1 b/Functions/IPAM/Prefix/New-NetboxIPAMPrefix.ps1 index c9c7577..ea728b0 100644 --- a/Functions/IPAM/Prefix/New-NetboxIPAMPrefix.ps1 +++ b/Functions/IPAM/Prefix/New-NetboxIPAMPrefix.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -13,47 +13,51 @@ function New-NetboxIPAMPrefix { + [CmdletBinding(ConfirmImpact = 'low', + SupportsShouldProcess = $true)] [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [string]$Prefix, - + [object]$Status = 'Active', - + [uint16]$Tenant, - + [object]$Role, - + [bool]$IsPool, - + [string]$Description, - + [uint16]$Site, - + [uint16]$VRF, - + [uint16]$VLAN, - + [hashtable]$Custom_Fields, - + [switch]$Raw ) - -# $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -PrefixStatus - + + # $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -PrefixStatus + <# # As of 2018/10/18, this does not appear to be a validated IPAM choice if ($null -ne $Role) { $PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -PrefixRole } #> - + $segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes')) - + $URIComponents = BuildURIComponents -URISegments $segments -ParametersDictionary $PSBoundParameters - + $URI = BuildNewURI -Segments $URIComponents.Segments - - InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw + + if ($PSCmdlet.ShouldProcess($Prefix, 'Create new Prefix')) { + InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw + } } \ No newline at end of file diff --git a/Functions/IPAM/Prefix/Set-NetboxIPAMPrefix.ps1 b/Functions/IPAM/Prefix/Set-NetboxIPAMPrefix.ps1 index 0670ad7..8a6b384 100644 --- a/Functions/IPAM/Prefix/Set-NetboxIPAMPrefix.ps1 +++ b/Functions/IPAM/Prefix/Set-NetboxIPAMPrefix.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2021 v5.8.186 @@ -20,39 +20,39 @@ function Set-NetboxIPAMPrefix { [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [uint16[]]$Id, - + [string]$Prefix, - + [string]$Status, - + [uint16]$Tenant, - + [uint16]$Site, - + [uint16]$VRF, - + [uint16]$VLAN, - + [object]$Role, - + [hashtable]$Custom_Fields, - + [string]$Description, - + [switch]$Is_Pool, - + [switch]$Force ) - + begin { # Write-Verbose "Validating enum properties" # $Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses', 0)) $Method = 'PATCH' - # + # # # Value validation # $ModelDefinition = GetModelDefinitionFromURIPath -Segments $Segments -Method $Method # $EnumProperties = GetModelEnumProperties -ModelDefinition $ModelDefinition - # + # # foreach ($Property in $EnumProperties.Keys) { # if ($PSBoundParameters.ContainsKey($Property)) { # Write-Verbose "Validating property [$Property] with value [$($PSBoundParameters.$Property)]" @@ -61,22 +61,22 @@ function Set-NetboxIPAMPrefix { # Write-Verbose "User did not provide a value for [$Property]" # } # } - # + # # Write-Verbose "Finished enum validation" } - + process { foreach ($PrefixId in $Id) { $Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes', $PrefixId)) - + Write-Verbose "Obtaining Prefix from ID $PrefixId" $CurrentPrefix = Get-NetboxIPAMPrefix -Id $PrefixId -ErrorAction Stop - + if ($Force -or $PSCmdlet.ShouldProcess($CurrentPrefix.Prefix, 'Set')) { $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force' - + $URI = BuildNewURI -Segments $URIComponents.Segments - + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method $Method } } diff --git a/Functions/IPAM/Role/Get-NetboxIPAMRole.ps1 b/Functions/IPAM/Role/Get-NetboxIPAMRole.ps1 index e7066c0..13a0861 100644 --- a/Functions/IPAM/Role/Get-NetboxIPAMRole.ps1 +++ b/Functions/IPAM/Role/Get-NetboxIPAMRole.ps1 @@ -3,93 +3,93 @@ function Get-NetboxIPAMRole { <# .SYNOPSIS Get IPAM Prefix/VLAN roles - + .DESCRIPTION A role indicates the function of a prefix or VLAN. For example, you might define Data, Voice, and Security roles. Generally, a prefix will be assigned the same functional role as the VLAN to which it is assigned (if any). - + .PARAMETER Id Unique ID - + .PARAMETER Query Search query - + .PARAMETER Name Role name - + .PARAMETER Slug Role URL slug - + .PARAMETER Brief Brief format - + .PARAMETER Limit Result limit - + .PARAMETER Offset Result offset - + .PARAMETER Raw A description of the Raw parameter. - + .EXAMPLE PS C:\> Get-NetboxIPAMRole - + .NOTES Additional information about the function. #> - + [CmdletBinding()] param ( [Parameter(ParameterSetName = 'Query', Position = 0)] [string]$Name, - + [Parameter(ParameterSetName = 'Query')] [string]$Query, - + [Parameter(ParameterSetName = 'ByID')] [uint32[]]$Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Slug, - + [Parameter(ParameterSetName = 'Query')] [switch]$Brief, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Limit, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Offset, - + [switch]$Raw ) - + switch ($PSCmdlet.ParameterSetName) { 'ById' { foreach ($Role_ID in $Id) { $Segments = [System.Collections.ArrayList]::new(@('ipam', 'roles', $Role_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(@('ipam', 'roles')) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $uri -Raw:$Raw - + break } } diff --git a/Functions/IPAM/VLAN/Get-NetboxIPAMVLAN.ps1 b/Functions/IPAM/VLAN/Get-NetboxIPAMVLAN.ps1 index 050d5bc..fa78c1f 100644 --- a/Functions/IPAM/VLAN/Get-NetboxIPAMVLAN.ps1 +++ b/Functions/IPAM/VLAN/Get-NetboxIPAMVLAN.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -20,89 +20,89 @@ function Get-NetboxIPAMVLAN { Position = 0)] [ValidateRange(1, 4096)] [uint16]$VID, - + [Parameter(ParameterSetName = 'ByID')] [uint32[]]$Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Query, - + [Parameter(ParameterSetName = 'Query')] [string]$Name, - + [Parameter(ParameterSetName = 'Query')] [string]$Tenant, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Tenant_Id, - + [Parameter(ParameterSetName = 'Query')] [string]$TenantGroup, - + [Parameter(ParameterSetName = 'Query')] [uint32]$TenantGroup_Id, - + [Parameter(ParameterSetName = 'Query')] [object]$Status, - + [Parameter(ParameterSetName = 'Query')] [string]$Region, - + [Parameter(ParameterSetName = 'Query')] [string]$Site, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Site_Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Group, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Group_Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Role, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Role_Id, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Limit, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Offset, - + [switch]$Raw ) - + # if ($null -ne $Status) { # $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus # } - + switch ($PSCmdlet.ParameterSetName) { 'ById' { foreach ($VLAN_ID in $Id) { $Segments = [System.Collections.ArrayList]::new(@('ipam', 'vlans', $VLAN_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(@('ipam', 'vlans')) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $uri -Raw:$Raw - + break } } diff --git a/Functions/IPAM/VLAN/New-NetboxIPAMVLAN.ps1 b/Functions/IPAM/VLAN/New-NetboxIPAMVLAN.ps1 index c846296..0af0499 100644 --- a/Functions/IPAM/VLAN/New-NetboxIPAMVLAN.ps1 +++ b/Functions/IPAM/VLAN/New-NetboxIPAMVLAN.ps1 @@ -1,79 +1,82 @@ function New-NetboxIPAMVLAN { -<# + <# .SYNOPSIS Create a new VLAN - + .DESCRIPTION Create a new VLAN in Netbox with a status of Active by default. - + .PARAMETER VID The VLAN ID. - + .PARAMETER Name The name of the VLAN. - + .PARAMETER Status Status of the VLAN. Defaults to Active - + .PARAMETER Tenant Tenant ID - + .PARAMETER Role Role such as anycast, loopback, etc... Defaults to nothing - + .PARAMETER Description Description of IP address - + .PARAMETER Custom_Fields Custom field hash table. Will be validated by the API service - + .PARAMETER Raw Return raw results from API service - + .PARAMETER Address IP address in CIDR notation: 192.168.1.1/24 - + .EXAMPLE PS C:\> Create-NetboxIPAMAddress - + .NOTES Additional information about the function. #> - - [CmdletBinding()] + + [CmdletBinding(ConfirmImpact = 'low', + SupportsShouldProcess = $true)] [OutputType([pscustomobject])] param ( [Parameter(Mandatory = $true)] [uint16]$VID, - + [Parameter(Mandatory = $true)] [string]$Name, - + [object]$Status = 'Active', - + [uint16]$Tenant, - + [object]$Role, - + [string]$Description, - + [hashtable]$Custom_Fields, - + [switch]$Raw ) - -# $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus -# -# if ($null -ne $Role) { -# $PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole -# } - + + # $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus + + # if ($null -ne $Role) { + # $PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole + # } + $segments = [System.Collections.ArrayList]::new(@('ipam', 'vlans')) - + $URIComponents = BuildURIComponents -URISegments $segments -ParametersDictionary $PSBoundParameters - + $URI = BuildNewURI -Segments $URIComponents.Segments - - InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw + + if ($PSCmdlet.ShouldProcess($nae, 'Create new Vlan $($vid)')) { + InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw + } } \ No newline at end of file diff --git a/Functions/Setup/Get-NetboxHostPort.ps1 b/Functions/Setup/Get-NetboxHostPort.ps1 index 691a7a3..8b56626 100644 --- a/Functions/Setup/Get-NetboxHostPort.ps1 +++ b/Functions/Setup/Get-NetboxHostPort.ps1 @@ -1,11 +1,11 @@ function Get-NetboxHostPort { [CmdletBinding()] param () - + Write-Verbose "Getting Netbox host port" if ($null -eq $script:NetboxConfig.HostPort) { throw "Netbox host port is not set! You may set it with Set-NetboxHostPort -Port 'https'" } - + $script:NetboxConfig.HostPort } \ No newline at end of file diff --git a/Functions/Setup/Get-NetboxHostScheme.ps1 b/Functions/Setup/Get-NetboxHostScheme.ps1 index ac396e0..ca37011 100644 --- a/Functions/Setup/Get-NetboxHostScheme.ps1 +++ b/Functions/Setup/Get-NetboxHostScheme.ps1 @@ -1,11 +1,11 @@ function Get-NetboxHostScheme { [CmdletBinding()] param () - + Write-Verbose "Getting Netbox host scheme" if ($null -eq $script:NetboxConfig.Hostscheme) { throw "Netbox host sceme is not set! You may set it with Set-NetboxHostScheme -Scheme 'https'" } - + $script:NetboxConfig.HostScheme } \ No newline at end of file diff --git a/Functions/Setup/Set-NetboxHostPort.ps1 b/Functions/Setup/Set-NetboxHostPort.ps1 index 5d2c0d6..3a88b06 100644 --- a/Functions/Setup/Set-NetboxHostPort.ps1 +++ b/Functions/Setup/Set-NetboxHostPort.ps1 @@ -7,7 +7,7 @@ [Parameter(Mandatory = $true)] [uint16]$Port ) - + if ($PSCmdlet.ShouldProcess('Netbox Port', 'Set')) { $script:NetboxConfig.HostPort = $Port $script:NetboxConfig.HostPort diff --git a/Functions/Setup/Set-NetboxHostScheme.ps1 b/Functions/Setup/Set-NetboxHostScheme.ps1 index f5a59c4..57b4112 100644 --- a/Functions/Setup/Set-NetboxHostScheme.ps1 +++ b/Functions/Setup/Set-NetboxHostScheme.ps1 @@ -8,12 +8,12 @@ [ValidateSet('https', 'http', IgnoreCase = $true)] [string]$Scheme = 'https' ) - + if ($PSCmdlet.ShouldProcess('Netbox Host Scheme', 'Set')) { if ($Scheme -eq 'http') { Write-Warning "Connecting via non-secure HTTP is not-recommended" } - + $script:NetboxConfig.HostScheme = $Scheme $script:NetboxConfig.HostScheme } diff --git a/Functions/Tenancy/Get-NetboxTenant.ps1 b/Functions/Tenancy/Get-NetboxTenant.ps1 index 85d110c..1e0732a 100644 --- a/Functions/Tenancy/Get-NetboxTenant.ps1 +++ b/Functions/Tenancy/Get-NetboxTenant.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -16,105 +16,105 @@ function Get-NetboxTenant { <# .SYNOPSIS Get a tenent from Netbox - + .DESCRIPTION A detailed description of the Get-NetboxTenant function. - + .PARAMETER Name The specific name of the tenant. Must match exactly as is defined in Netbox - + .PARAMETER Id The database ID of the tenant - + .PARAMETER Query A standard search query that will match one or more tenants. - + .PARAMETER Slug The specific slug of the tenant. Must match exactly as is defined in Netbox - + .PARAMETER Group The specific group as defined in Netbox. - + .PARAMETER GroupID The database ID of the group in Netbox - + .PARAMETER CustomFields Hashtable in the format @{"field_name" = "value"} to search - + .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-NetboxTenant - + .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]$Group, - + [Parameter(ParameterSetName = 'Query')] [uint16]$GroupID, - + [Parameter(ParameterSetName = 'Query')] [hashtable]$CustomFields, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Limit, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Offset, - + [switch]$Raw ) - + switch ($PSCmdlet.ParameterSetName) { 'ById' { foreach ($Tenant_ID in $Id) { $Segments = [System.Collections.ArrayList]::new(@('tenancy', 'tenants', $Tenant_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', 'tenants')) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $uri -Raw:$Raw - + break } } diff --git a/Functions/Tenancy/Tenancy.ps1 b/Functions/Tenancy/Tenancy.ps1 index 1c8de41..ef5e187 100644 --- a/Functions/Tenancy/Tenancy.ps1 +++ b/Functions/Tenancy/Tenancy.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.152 diff --git a/Functions/Virtualization/VirtualMachine/Get-NetboxVirtualMachine.ps1 b/Functions/Virtualization/VirtualMachine/Get-NetboxVirtualMachine.ps1 index c84c60a..34884e2 100644 --- a/Functions/Virtualization/VirtualMachine/Get-NetboxVirtualMachine.ps1 +++ b/Functions/Virtualization/VirtualMachine/Get-NetboxVirtualMachine.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -13,143 +13,145 @@ function Get-NetboxVirtualMachine { -<# + <# .SYNOPSIS Obtains virtual machines from Netbox. - + .DESCRIPTION Obtains one or more virtual machines based on provided filters. - + .PARAMETER Limit Number of results to return per page - + .PARAMETER Offset The initial index from which to return the results - + .PARAMETER Query A general query used to search for a VM - + .PARAMETER Name Name of the VM - + .PARAMETER Id Database ID of the VM - + .PARAMETER Status Status of the VM - + .PARAMETER Tenant String value of tenant - + .PARAMETER Tenant_ID Database ID of the tenant. - + .PARAMETER Platform String value of the platform - + .PARAMETER Platform_ID Database ID of the platform - + .PARAMETER Cluster_Group String value of the cluster group. - + .PARAMETER Cluster_Group_Id Database ID of the cluster group. - + .PARAMETER Cluster_Type String value of the Cluster type. - + .PARAMETER Cluster_Type_Id Database ID of the cluster type. - + .PARAMETER Cluster_Id Database ID of the cluster. - + .PARAMETER Site String value of the site. - + .PARAMETER Site_Id Database ID of the site. - + .PARAMETER Role String value of the role. - + .PARAMETER Role_Id Database ID of the role. - + .PARAMETER Raw A description of the Raw parameter. - + .PARAMETER TenantID Database ID of tenant - + .PARAMETER PlatformID Database ID of the platform - + .PARAMETER id__in Database IDs of VMs - + .EXAMPLE PS C:\> Get-NetboxVirtualMachine - + .NOTES Additional information about the function. #> - + [CmdletBinding()] param ( [Alias('q')] [string]$Query, - + [string]$Name, - + [uint16[]]$Id, - + [object]$Status, - + [string]$Tenant, - + [uint16]$Tenant_ID, - + [string]$Platform, - + [uint16]$Platform_ID, - + [string]$Cluster_Group, - + [uint16]$Cluster_Group_Id, - + [string]$Cluster_Type, - + [uint16]$Cluster_Type_Id, - + [uint16]$Cluster_Id, - + [string]$Site, - + [uint16]$Site_Id, - + [string]$Role, - + [uint16]$Role_Id, - + [uint16]$Limit, - + [uint16]$Offset, - + [switch]$Raw ) - - if ($null -ne $Status) { - $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus + + process { + if ($null -ne $Status) { + $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus + } + + $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines')) + + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters + + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters + + InvokeNetboxRequest -URI $uri -Raw:$Raw } - - $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines')) - - $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - - $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - - InvokeNetboxRequest -URI $uri -Raw:$Raw } \ No newline at end of file diff --git a/Functions/Virtualization/VirtualMachine/New-NetboxVirtualMachine.ps1 b/Functions/Virtualization/VirtualMachine/New-NetboxVirtualMachine.ps1 index 6798c36..dbab718 100644 --- a/Functions/Virtualization/VirtualMachine/New-NetboxVirtualMachine.ps1 +++ b/Functions/Virtualization/VirtualMachine/New-NetboxVirtualMachine.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -13,55 +13,58 @@ function New-NetboxVirtualMachine { - [CmdletBinding()] + [CmdletBinding(ConfirmImpact = 'low', + SupportsShouldProcess = $true)] [OutputType([pscustomobject])] param ( [Parameter(Mandatory = $true)] [string]$Name, - + [Parameter(Mandatory = $true)] [uint16]$Cluster, - + [uint16]$Tenant, - + [object]$Status = 'Active', - + [uint16]$Role, - + [uint16]$Platform, - + [uint16]$vCPUs, - + [uint16]$Memory, - + [uint16]$Disk, - + [uint16]$Primary_IP4, - + [uint16]$Primary_IP6, - + [hashtable]$Custom_Fields, - + [string]$Comments ) - -# $ModelDefinition = $script:NetboxConfig.APIDefinition.definitions.WritableVirtualMachineWithConfigContext -# -# # Validate the status against the APIDefinition -# if ($ModelDefinition.properties.status.enum -inotcontains $Status) { -# throw ("Invalid value [] for Status. Must be one of []" -f $Status, ($ModelDefinition.properties.status.enum -join ', ')) -# } -# + + # $ModelDefinition = $script:NetboxConfig.APIDefinition.definitions.WritableVirtualMachineWithConfigContext + + # # Validate the status against the APIDefinition + # if ($ModelDefinition.properties.status.enum -inotcontains $Status) { + # throw ("Invalid value [] for Status. Must be one of []" -f $Status, ($ModelDefinition.properties.status.enum -join ', ')) + # } + #$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus - + $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines')) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - + $URI = BuildNewURI -Segments $URIComponents.Segments - - InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters + + if ($PSCmdlet.ShouldProcess($name, 'Create new Virtual Machine')) { + InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters + } } diff --git a/Functions/Virtualization/VirtualMachine/Remove-NetboxVirtualMachine.ps1 b/Functions/Virtualization/VirtualMachine/Remove-NetboxVirtualMachine.ps1 index 4e599a3..b2cb192 100644 --- a/Functions/Virtualization/VirtualMachine/Remove-NetboxVirtualMachine.ps1 +++ b/Functions/Virtualization/VirtualMachine/Remove-NetboxVirtualMachine.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -16,23 +16,23 @@ function Remove-NetboxVirtualMachine { <# .SYNOPSIS Delete a virtual machine - + .DESCRIPTION Deletes a virtual machine from Netbox by ID - + .PARAMETER Id Database ID of the virtual machine - + .PARAMETER Force Force deletion without any prompts - + .EXAMPLE PS C:\> Remove-NetboxVirtualMachine -Id $value1 - + .NOTES Additional information about the function. #> - + [CmdletBinding(ConfirmImpact = 'High', SupportsShouldProcess = $true)] param @@ -40,29 +40,29 @@ function Remove-NetboxVirtualMachine { [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [uint16[]]$Id, - + [switch]$Force ) - + begin { - + } - + process { foreach ($VMId in $Id) { $CurrentVM = Get-NetboxVirtualMachine -Id $VMId -ErrorAction Stop - + if ($Force -or $pscmdlet.ShouldProcess("$($CurrentVM.Name)/$($CurrentVM.Id)", "Remove")) { $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines', $CurrentVM.Id)) - + $URI = BuildNewURI -Segments $Segments - + InvokeNetboxRequest -URI $URI -Method DELETE } } } - + end { - + } } \ No newline at end of file diff --git a/Functions/Virtualization/VirtualMachine/Set-NetboxVirtualMachine.ps1 b/Functions/Virtualization/VirtualMachine/Set-NetboxVirtualMachine.ps1 index abfaac5..bba99e7 100644 --- a/Functions/Virtualization/VirtualMachine/Set-NetboxVirtualMachine.ps1 +++ b/Functions/Virtualization/VirtualMachine/Set-NetboxVirtualMachine.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -14,59 +14,61 @@ function Set-NetboxVirtualMachine { [CmdletBinding(ConfirmImpact = 'Medium', - SupportsShouldProcess = $true)] + SupportsShouldProcess = $true)] param ( [Parameter(Mandatory = $true, - ValueFromPipelineByPropertyName = $true)] + ValueFromPipelineByPropertyName = $true)] [uint16]$Id, - + [string]$Name, - + [uint16]$Role, - + [uint16]$Cluster, - + [object]$Status, - + [uint16]$Platform, - + [uint16]$Primary_IP4, - + [uint16]$Primary_IP6, - + [byte]$VCPUs, - + [uint16]$Memory, - + [uint16]$Disk, - + [uint16]$Tenant, - + [string]$Comments, - + [hashtable]$Custom_Fields, - + [switch]$Force ) - -# if ($null -ne $Status) { -# $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus -# } -# - $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines', $Id)) - - Write-Verbose "Obtaining VM from ID $Id" - - #$CurrentVM = Get-NetboxVirtualMachine -Id $Id -ErrorAction Stop - - Write-Verbose "Finished obtaining VM" - - if ($Force -or $pscmdlet.ShouldProcess($ID, "Set properties on VM ID")) { - $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force' - - $URI = BuildNewURI -Segments $URIComponents.Segments - - InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH + + # if ($null -ne $Status) { + # $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus + # } + + process { + $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines', $Id)) + + Write-Verbose "Obtaining VM from ID $Id" + + #$CurrentVM = Get-NetboxVirtualMachine -Id $Id -ErrorAction Stop + + Write-Verbose "Finished obtaining VM" + + if ($Force -or $pscmdlet.ShouldProcess($ID, "Set properties on VM ID")) { + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force' + + $URI = BuildNewURI -Segments $URIComponents.Segments + + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH + } } } \ No newline at end of file diff --git a/Functions/Virtualization/VirtualMachineInterface/Add-NetboxVirtualMachineInterface.ps1 b/Functions/Virtualization/VirtualMachineInterface/Add-NetboxVirtualMachineInterface.ps1 index f9b0b56..e197244 100644 --- a/Functions/Virtualization/VirtualMachineInterface/Add-NetboxVirtualMachineInterface.ps1 +++ b/Functions/Virtualization/VirtualMachineInterface/Add-NetboxVirtualMachineInterface.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -18,28 +18,28 @@ function Add-NetboxVirtualMachineInterface { ( [Parameter(Mandatory = $true)] [string]$Name, - + [Parameter(Mandatory = $true)] [uint16]$Virtual_Machine, - + [boolean]$Enabled = $true, - + [string]$MAC_Address, - + [uint16]$MTU, - + [string]$Description, - + [switch]$Raw ) - + $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces')) - + $PSBoundParameters.Enabled = $Enabled - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - + $uri = BuildNewURI -Segments $URIComponents.Segments - + InvokeNetboxRequest -URI $uri -Method POST -Body $URIComponents.Parameters } \ No newline at end of file diff --git a/Functions/Virtualization/VirtualMachineInterface/Get-NetboxVirtualMachineInterface.ps1 b/Functions/Virtualization/VirtualMachineInterface/Get-NetboxVirtualMachineInterface.ps1 index 0b0c3c4..1b85127 100644 --- a/Functions/Virtualization/VirtualMachineInterface/Get-NetboxVirtualMachineInterface.ps1 +++ b/Functions/Virtualization/VirtualMachineInterface/Get-NetboxVirtualMachineInterface.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -13,82 +13,84 @@ function Get-NetboxVirtualMachineInterface { -<# + <# .SYNOPSIS Gets VM interfaces - + .DESCRIPTION Obtains the interface objects for one or more VMs - + .PARAMETER Limit Number of results to return per page. - + .PARAMETER Offset The initial index from which to return the results. - + .PARAMETER Id Database ID of the interface - + .PARAMETER Name Name of the interface - + .PARAMETER Enabled True/False if the interface is enabled - + .PARAMETER MTU Maximum Transmission Unit size. Generally 1500 or 9000 - + .PARAMETER Virtual_Machine_Id ID of the virtual machine to which the interface(s) are assigned. - + .PARAMETER Virtual_Machine Name of the virtual machine to get interfaces - + .PARAMETER MAC_Address MAC address assigned to the interface - + .PARAMETER Raw A description of the Raw parameter. - + .EXAMPLE PS C:\> Get-NetboxVirtualMachineInterface - + .NOTES Additional information about the function. #> - + [CmdletBinding()] param ( [Parameter(ValueFromPipeline = $true)] [uint16]$Id, - + [string]$Name, - + [string]$Query, - + [boolean]$Enabled, - + [uint16]$MTU, - + [uint16]$Virtual_Machine_Id, - + [string]$Virtual_Machine, - + [string]$MAC_Address, - + [uint16]$Limit, - + [uint16]$Offset, - + [switch]$Raw ) - - $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces')) - - $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - - $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - - InvokeNetboxRequest -URI $uri -Raw:$Raw + + process { + $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces')) + + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters + + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters + + InvokeNetboxRequest -URI $uri -Raw:$Raw + } } \ No newline at end of file diff --git a/Functions/Virtualization/VirtualMachineInterface/Set-NetboxVirtualMachineInterface.ps1 b/Functions/Virtualization/VirtualMachineInterface/Set-NetboxVirtualMachineInterface.ps1 index ab2ef49..db16b46 100644 --- a/Functions/Virtualization/VirtualMachineInterface/Set-NetboxVirtualMachineInterface.ps1 +++ b/Functions/Virtualization/VirtualMachineInterface/Set-NetboxVirtualMachineInterface.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -21,45 +21,45 @@ function Set-NetboxVirtualMachineInterface { [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [uint16[]]$Id, - + [string]$Name, - + [string]$MAC_Address, - + [uint16]$MTU, - + [string]$Description, - + [boolean]$Enabled, - + [uint16]$Virtual_Machine, - + [switch]$Force ) - + begin { - + } - + process { foreach ($VMI_ID in $Id) { Write-Verbose "Obtaining VM Interface..." $CurrentVMI = Get-NetboxVirtualMachineInterface -Id $VMI_ID -ErrorAction Stop Write-Verbose "Finished obtaining VM Interface" - + $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces', $CurrentVMI.Id)) - + if ($Force -or $pscmdlet.ShouldProcess("Interface $($CurrentVMI.Id) on VM $($CurrentVMI.Virtual_Machine.Name)", "Set")) { $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force' - + $URI = BuildNewURI -Segments $URIComponents.Segments - + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH } } } - + end { - + } } \ No newline at end of file diff --git a/Functions/Virtualization/VirtualizationCluster/Get-NetboxVirtualizationCluster.ps1 b/Functions/Virtualization/VirtualizationCluster/Get-NetboxVirtualizationCluster.ps1 index bb373a6..68e7f10 100644 --- a/Functions/Virtualization/VirtualizationCluster/Get-NetboxVirtualizationCluster.ps1 +++ b/Functions/Virtualization/VirtualizationCluster/Get-NetboxVirtualizationCluster.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -16,87 +16,87 @@ function Get-NetboxVirtualizationCluster { <# .SYNOPSIS Obtains virtualization clusters from Netbox. - + .DESCRIPTION Obtains one or more virtualization clusters based on provided filters. - + .PARAMETER Limit Number of results to return per page - + .PARAMETER Offset The initial index from which to return the results - + .PARAMETER Query A general query used to search for a cluster - + .PARAMETER Name Name of the cluster - + .PARAMETER Id Database ID(s) of the cluster - + .PARAMETER Group String value of the cluster group. - + .PARAMETER Group_Id Database ID of the cluster group. - + .PARAMETER Type String value of the Cluster type. - + .PARAMETER Type_Id Database ID of the cluster type. - + .PARAMETER Site String value of the site. - + .PARAMETER Site_Id Database ID of the site. - + .PARAMETER Raw A description of the Raw parameter. - + .EXAMPLE PS C:\> Get-NetboxVirtualizationCluster - + .NOTES Additional information about the function. #> - + [CmdletBinding()] param ( [string]$Name, - + [Alias('q')] [string]$Query, - + [uint16[]]$Id, - + [string]$Group, - + [uint16]$Group_Id, - + [string]$Type, - + [uint16]$Type_Id, - + [string]$Site, - + [uint16]$Site_Id, - + [uint16]$Limit, - + [uint16]$Offset, - + [switch]$Raw ) - + $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'clusters')) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $uri -Raw:$Raw } \ No newline at end of file diff --git a/Functions/Virtualization/VirtualizationCluster/Get-NetboxVirtualizationClusterGroup.ps1 b/Functions/Virtualization/VirtualizationCluster/Get-NetboxVirtualizationClusterGroup.ps1 index 467e716..0269f5a 100644 --- a/Functions/Virtualization/VirtualizationCluster/Get-NetboxVirtualizationClusterGroup.ps1 +++ b/Functions/Virtualization/VirtualizationCluster/Get-NetboxVirtualizationClusterGroup.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -17,27 +17,27 @@ function Get-NetboxVirtualizationClusterGroup { param ( [string]$Name, - + [string]$Slug, - + [string]$Description, - + [string]$Query, - + [uint32[]]$Id, - + [uint16]$Limit, - + [uint16]$Offset, - + [switch]$Raw ) - + $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'cluster-groups')) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $uri -Raw:$Raw } \ No newline at end of file diff --git a/NetboxPS/NetboxPS.psm1 b/NetboxPS/NetboxPS.psm1 index 1b31bb1..c83401d 100644 --- a/NetboxPS/NetboxPS.psm1 +++ b/NetboxPS/NetboxPS.psm1 @@ -2,7 +2,7 @@ #region File Add-NetboxDCIMInterface.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -23,67 +23,67 @@ function Add-NetboxDCIMInterface { ( [Parameter(Mandatory = $true)] [uint16]$Device, - + [Parameter(Mandatory = $true)] [string]$Name, - + [bool]$Enabled, - + [object]$Form_Factor, - + [uint16]$MTU, - + [string]$MAC_Address, - + [bool]$MGMT_Only, - + [uint16]$LAG, - + [string]$Description, - + [ValidateSet('Access', 'Tagged', 'Tagged All', '100', '200', '300', IgnoreCase = $true)] [string]$Mode, - + [ValidateRange(1, 4094)] [uint16]$Untagged_VLAN, - + [ValidateRange(1, 4094)] [uint16[]]$Tagged_VLANs ) - + # if ($null -ne $Form_Factor) { # $PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor # } - + if (-not [System.String]::IsNullOrWhiteSpace($Mode)) { $PSBoundParameters.Mode = switch ($Mode) { 'Access' { 100 break } - + 'Tagged' { 200 break } - + 'Tagged All' { 300 break } - + default { $_ } } } - + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces')) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters - + $URI = BuildNewURI -Segments $URIComponents.Segments - + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST } @@ -91,7 +91,7 @@ function Add-NetboxDCIMInterface { #region File Add-NetboxDCIMInterfaceConnection.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -109,53 +109,53 @@ function Add-NetboxDCIMInterfaceConnection { <# .SYNOPSIS Create a new connection between two interfaces - + .DESCRIPTION Create a new connection between two interfaces - + .PARAMETER Connection_Status Is it connected or planned? - + .PARAMETER Interface_A Database ID of interface A - + .PARAMETER Interface_B Database ID of interface B - + .EXAMPLE PS C:\> Add-NetboxDCIMInterfaceConnection -Interface_A $value1 -Interface_B $value2 - + .NOTES Additional information about the function. #> - + [CmdletBinding()] [OutputType([pscustomobject])] param ( [object]$Connection_Status, - + [Parameter(Mandatory = $true)] [uint16]$Interface_A, - + [Parameter(Mandatory = $true)] [uint16]$Interface_B ) - + if ($null -ne $Connection_Status) { $PSBoundParameters.Connection_Status = ValidateDCIMChoice -ProvidedValue $Connection_Status -InterfaceConnectionStatus } - + # Verify if both Interfaces exist $I_A = Get-NetboxDCIMInterface -Id $Interface_A -ErrorAction Stop $I_B = Get-NetboxDCIMInterface -Id $Interface_B -ErrorAction Stop - + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections')) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters - + $URI = BuildNewURI -Segments $URIComponents.Segments - + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST } @@ -163,7 +163,7 @@ function Add-NetboxDCIMInterfaceConnection { #region File Add-NetboxVirtualMachineInterface.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -183,29 +183,29 @@ function Add-NetboxVirtualMachineInterface { ( [Parameter(Mandatory = $true)] [string]$Name, - + [Parameter(Mandatory = $true)] [uint16]$Virtual_Machine, - + [boolean]$Enabled = $true, - + [string]$MAC_Address, - + [uint16]$MTU, - + [string]$Description, - + [switch]$Raw ) - + $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces')) - + $PSBoundParameters.Enabled = $Enabled - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - + $uri = BuildNewURI -Segments $URIComponents.Segments - + InvokeNetboxRequest -URI $uri -Method POST -Body $URIComponents.Parameters } @@ -213,7 +213,7 @@ function Add-NetboxVirtualMachineInterface { #region File BuildNewURI.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -231,77 +231,77 @@ function BuildNewURI { <# .SYNOPSIS Create a new URI for Netbox - + .DESCRIPTION Internal function used to build a URIBuilder object. - + .PARAMETER Hostname Hostname of the Netbox API - + .PARAMETER Segments Array of strings for each segment in the URL path - + .PARAMETER Parameters Hashtable of query parameters to include - + .PARAMETER HTTPS Whether to use HTTPS or HTTP - + .PARAMETER Port A description of the Port parameter. - + .PARAMETER APIInfo A description of the APIInfo parameter. - + .EXAMPLE PS C:\> BuildNewURI - + .NOTES Additional information about the function. #> - + [CmdletBinding()] [OutputType([System.UriBuilder])] param ( [Parameter(Mandatory = $false)] [string[]]$Segments, - + [Parameter(Mandatory = $false)] [hashtable]$Parameters, - + [switch]$SkipConnectedCheck ) - + Write-Verbose "Building URI" - + if (-not $SkipConnectedCheck) { # There is no point in continuing if we have not successfully connected to an API $null = CheckNetboxIsConnected } - + # Begin a URI builder with HTTP/HTTPS and the provided hostname $uriBuilder = [System.UriBuilder]::new($script:NetboxConfig.HostScheme, $script:NetboxConfig.Hostname, $script:NetboxConfig.HostPort) - + # Generate the path by trimming excess slashes and whitespace from the $segments[] and joining together $uriBuilder.Path = "api/{0}/" -f ($Segments.ForEach({ $_.trim('/').trim() }) -join '/') - + Write-Verbose " URIPath: $($uriBuilder.Path)" - + if ($parameters) { # Loop through the parameters and use the HttpUtility to create a Query string [System.Collections.Specialized.NameValueCollection]$URIParams = [System.Web.HttpUtility]::ParseQueryString([String]::Empty) - + foreach ($param in $Parameters.GetEnumerator()) { Write-Verbose " Adding URI parameter $($param.Key):$($param.Value)" $URIParams[$param.Key] = $param.Value } - + $uriBuilder.Query = $URIParams.ToString() } - + Write-Verbose " Completed building URIBuilder" # Return the entire UriBuilder object $uriBuilder @@ -311,7 +311,7 @@ function BuildNewURI { #region File BuildURIComponents.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -332,30 +332,30 @@ function BuildURIComponents { ( [Parameter(Mandatory = $true)] [System.Collections.ArrayList]$URISegments, - + [Parameter(Mandatory = $true)] [object]$ParametersDictionary, - + [string[]]$SkipParameterByName ) - + Write-Verbose "Building URI components" - + $URIParameters = @{ } - + foreach ($CmdletParameterName in $ParametersDictionary.Keys) { if ($CmdletParameterName -in $script:CommonParameterNames) { # These are common parameters and should not be appended to the URI Write-Debug "Skipping common parameter $CmdletParameterName" continue } - + if ($CmdletParameterName -in $SkipParameterByName) { Write-Debug "Skipping parameter $CmdletParameterName by SkipParameterByName" continue } - + switch ($CmdletParameterName) { "id" { # Check if there is one or more values for Id and build a URI or query as appropriate @@ -366,26 +366,26 @@ function BuildURIComponents { Write-Verbose " Adding ID to segments" [void]$uriSegments.Add($ParametersDictionary[$CmdletParameterName]) } - + break } - + 'Query' { Write-Verbose " Adding query parameter" $URIParameters['q'] = $ParametersDictionary[$CmdletParameterName] break } - + 'CustomFields' { Write-Verbose " Adding custom field query parameters" foreach ($field in $ParametersDictionary[$CmdletParameterName].GetEnumerator()) { Write-Verbose " Adding parameter 'cf_$($field.Key) = $($field.Value)" $URIParameters["cf_$($field.Key.ToLower())"] = $field.Value } - + break } - + default { Write-Verbose " Adding $($CmdletParameterName.ToLower()) parameter" $URIParameters[$CmdletParameterName.ToLower()] = $ParametersDictionary[$CmdletParameterName] @@ -393,7 +393,7 @@ function BuildURIComponents { } } } - + return @{ 'Segments' = [System.Collections.ArrayList]$URISegments 'Parameters' = $URIParameters @@ -404,7 +404,7 @@ function BuildURIComponents { #region File CheckNetboxIsConnected.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -421,7 +421,7 @@ function BuildURIComponents { function CheckNetboxIsConnected { [CmdletBinding()] param () - + Write-Verbose "Checking connection status" if (-not $script:NetboxConfig.Connected) { throw "Not connected to a Netbox API! Please run 'Connect-NetboxAPI'" @@ -432,7 +432,7 @@ function CheckNetboxIsConnected { #region File Circuits.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.148 @@ -457,7 +457,7 @@ function Clear-NetboxCredential { ( [switch]$Force ) - + if ($Force -or ($PSCmdlet.ShouldProcess('Netbox Credentials', 'Clear'))) { $script:NetboxConfig.Credential = $null } @@ -631,7 +631,7 @@ function Connect-NetboxAPI { #region File CreateEnum.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -651,13 +651,13 @@ function CreateEnum { ( [Parameter(Mandatory = $true)] [string]$EnumName, - + [Parameter(Mandatory = $true)] [pscustomobject]$Values, - + [switch]$PassThru ) - + $definition = @" public enum $EnumName {`n$(foreach ($value in $values) { @@ -677,7 +677,7 @@ public enum $EnumName #region File Get-ModelDefinition.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 @@ -699,47 +699,47 @@ function Get-ModelDefinition { [Parameter(ParameterSetName = 'ByName', Mandatory = $true)] [string]$ModelName, - + [Parameter(ParameterSetName = 'ByPath', Mandatory = $true)] [string]$URIPath, - + [Parameter(ParameterSetName = 'ByPath')] [string]$Method = "post" ) - + switch ($PsCmdlet.ParameterSetName) { 'ByName' { $script:NetboxConfig.APIDefinition.definitions.$ModelName break } - + 'ByPath' { switch ($Method) { "get" { - + break } - + "post" { if (-not $URIPath.StartsWith('/')) { $URIPath = "/$URIPath" } - + if (-not $URIPath.EndsWith('/')) { $URIPath = "$URIPath/" } - + $ModelName = $script:NetboxConfig.APIDefinition.paths.$URIPath.post.parameters.schema.'$ref'.split('/')[-1] $script:NetboxConfig.APIDefinition.definitions.$ModelName break } } - + break } } - + } #endregion @@ -780,7 +780,7 @@ function Get-NetboxAPIDefinition { #region File GetNetboxAPIErrorBody.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -800,10 +800,10 @@ function GetNetboxAPIErrorBody { [Parameter(Mandatory = $true)] [System.Net.HttpWebResponse]$Response ) - + # This takes the $Response stream and turns it into a useable object... generally a string. # If the body is JSON, you should be able to use ConvertFrom-Json - + $reader = New-Object System.IO.StreamReader($Response.GetResponseStream()) $reader.BaseStream.Position = 0 $reader.DiscardBufferedData() @@ -814,7 +814,7 @@ function GetNetboxAPIErrorBody { #region File Get-NetboxCircuit.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -832,115 +832,115 @@ function Get-NetboxCircuit { <# .SYNOPSIS Gets one or more circuits - + .DESCRIPTION A detailed description of the Get-NetboxCircuit function. - + .PARAMETER Id Database ID of circuit. This will query for exactly the IDs provided - + .PARAMETER CID Circuit ID - + .PARAMETER InstallDate Date of installation - + .PARAMETER CommitRate Committed rate in Kbps - + .PARAMETER Query A raw search query... As if you were searching the web site - + .PARAMETER Provider The name or ID of the provider. Provide either [string] or [int]. String will search provider names, integer will search database IDs - + .PARAMETER Type Type of circuit. Provide either [string] or [int]. String will search provider type names, integer will search database IDs - + .PARAMETER Site Location/site of circuit. Provide either [string] or [int]. String will search site names, integer will search database IDs - + .PARAMETER Tenant Tenant assigned to circuit. Provide either [string] or [int]. String will search tenant names, integer will search database IDs - + .PARAMETER Limit A description of the Limit parameter. - + .PARAMETER Offset A description of the Offset parameter. - + .PARAMETER Raw A description of the Raw parameter. - + .PARAMETER ID__IN Multiple unique DB IDs to retrieve - + .EXAMPLE PS C:\> Get-NetboxCircuit - + .NOTES Additional information about the function. #> - + [CmdletBinding(DefaultParameterSetName = 'Query')] param ( [Parameter(ParameterSetName = 'ById')] [uint16[]]$Id, - + [Parameter(ParameterSetName = 'Query')] [string]$CID, - + [Parameter(ParameterSetName = 'Query')] [datetime]$InstallDate, - + [Parameter(ParameterSetName = 'Query')] [uint32]$CommitRate, - + [Parameter(ParameterSetName = 'Query')] [string]$Query, - + [Parameter(ParameterSetName = 'Query')] [object]$Provider, - + [Parameter(ParameterSetName = 'Query')] [object]$Type, - + [Parameter(ParameterSetName = 'Query')] [string]$Site, - + [Parameter(ParameterSetName = 'Query')] [string]$Tenant, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Limit, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Offset, - + [switch]$Raw ) - + switch ($PSCmdlet.ParameterSetName) { 'ById' { foreach ($i in $ID) { $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits', $i)) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id" - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } } - + default { $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits')) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } } @@ -950,7 +950,7 @@ function Get-NetboxCircuit { #region File Get-NetboxCircuitProvider.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 @@ -972,52 +972,52 @@ function Get-NetboxCircuitProvider { [Parameter(ParameterSetName = 'ById', Mandatory = $true)] [uint16[]]$Id, - + [Parameter(ParameterSetName = 'Query', Mandatory = $false)] [string]$Name, - + [Parameter(ParameterSetName = 'Query')] [string]$Query, - + [Parameter(ParameterSetName = 'Query')] [string]$Slug, - + [Parameter(ParameterSetName = 'Query')] [string]$ASN, - + [Parameter(ParameterSetName = 'Query')] [string]$Account, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Limit, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Offset, - + [switch]$Raw ) - + switch ($PSCmdlet.ParameterSetName) { 'ById' { foreach ($i in $ID) { $Segments = [System.Collections.ArrayList]::new(@('circuits', 'providers', $i)) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id" - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } } - + default { $Segments = [System.Collections.ArrayList]::new(@('circuits', 'providers')) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } } @@ -1027,7 +1027,7 @@ function Get-NetboxCircuitProvider { #region File Get-NetboxCircuitTermination.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 @@ -1049,58 +1049,58 @@ function Get-NetboxCircuitTermination { [Parameter(ParameterSetName = 'ById', ValueFromPipelineByPropertyName = $true)] [uint32[]]$Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Circuit_ID, - + [Parameter(ParameterSetName = 'Query')] [string]$Term_Side, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Port_Speed, - + [Parameter(ParameterSetName = 'Query')] [string]$Query, - + [Parameter(ParameterSetName = 'Query')] [string]$Site_ID, - + [Parameter(ParameterSetName = 'Query')] [string]$Site, - + [Parameter(ParameterSetName = 'Query')] [string]$XConnect_ID, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Limit, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Offset, - + [switch]$Raw ) - + process { switch ($PSCmdlet.ParameterSetName) { 'ById' { foreach ($i in $ID) { $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuit-terminations', $i)) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id" - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } } - + default { $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuit-terminations')) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } } @@ -1111,7 +1111,7 @@ function Get-NetboxCircuitTermination { #region File Get-NetboxCircuitType.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 @@ -1132,45 +1132,45 @@ function Get-NetboxCircuitType { ( [Parameter(ParameterSetName = 'ById')] [uint16[]]$Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Name, - + [Parameter(ParameterSetName = 'Query')] [string]$Slug, - + [Parameter(ParameterSetName = 'Query')] [string]$Query, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Limit, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Offset, - + [switch]$Raw ) - + switch ($PSCmdlet.ParameterSetName) { 'ById' { foreach ($i in $ID) { $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuit_types', $i)) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id" - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } } - + default { $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuit-types')) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } } @@ -1204,7 +1204,7 @@ function Get-NetboxCredential { #region File Get-NetboxDCIMDevice.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -1224,83 +1224,83 @@ function Get-NetboxDCIMDevice { param ( [uint16]$Limit, - + [uint16]$Offset, - + [Parameter(ValueFromPipelineByPropertyName = $true)] [uint16[]]$Id, - + [string]$Query, - + [string]$Name, - + [uint16]$Manufacturer_Id, - + [string]$Manufacturer, - + [uint16]$Device_Type_Id, - + [uint16]$Role_Id, - + [string]$Role, - + [uint16]$Tenant_Id, - + [string]$Tenant, - + [uint16]$Platform_Id, - + [string]$Platform, - + [string]$Asset_Tag, - + [uint16]$Site_Id, - + [string]$Site, - + [uint16]$Rack_Group_Id, - + [uint16]$Rack_Id, - + [uint16]$Cluster_Id, - + [uint16]$Model, - + [object]$Status, - + [bool]$Is_Full_Depth, - + [bool]$Is_Console_Server, - + [bool]$Is_PDU, - + [bool]$Is_Network_Device, - + [string]$MAC_Address, - + [bool]$Has_Primary_IP, - + [uint16]$Virtual_Chassis_Id, - + [uint16]$Position, - + [string]$Serial, - + [switch]$Raw ) - + #endregion Parameters - + if ($null -ne $Status) { $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus } - + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices')) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw' - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } @@ -1308,7 +1308,7 @@ function Get-NetboxDCIMDevice { #region File Get-NetboxDCIMDeviceRole.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -1327,45 +1327,45 @@ function Get-NetboxDCIMDeviceRole { param ( [uint16]$Limit, - + [uint16]$Offset, - + [Parameter(ParameterSetName = 'ById')] [uint16[]]$Id, - + [string]$Name, - + [string]$Slug, - + [string]$Color, - + [bool]$VM_Role, - + [switch]$Raw ) - + switch ($PSCmdlet.ParameterSetName) { 'ById' { foreach ($DRId in $Id) { $Segments = [System.Collections.ArrayList]::new(@('dcim', 'device-roles', $DRId)) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Raw' - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } - + break } - + default { $Segments = [System.Collections.ArrayList]::new(@('dcim', 'device-roles')) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw' - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } } @@ -1375,7 +1375,7 @@ function Get-NetboxDCIMDeviceRole { #region File Get-NetboxDCIMDeviceType.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -1395,45 +1395,45 @@ function Get-NetboxDCIMDeviceType { param ( [uint16]$Offset, - + [uint16]$Limit, - + [uint16[]]$Id, - + [string]$Query, - + [string]$Slug, - + [string]$Manufacturer, - + [uint16]$Manufacturer_Id, - + [string]$Model, - + [string]$Part_Number, - + [uint16]$U_Height, - + [bool]$Is_Full_Depth, - + [bool]$Is_Console_Server, - + [bool]$Is_PDU, - + [bool]$Is_Network_Device, - + [uint16]$Subdevice_Role, - + [switch]$Raw ) #endregion Parameters - + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'device-types')) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw' - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } @@ -1441,7 +1441,7 @@ function Get-NetboxDCIMDeviceType { #region File Get-NetboxDCIMInterface.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -1461,45 +1461,45 @@ function Get-NetboxDCIMInterface { param ( [uint16]$Limit, - + [uint16]$Offset, - + [Parameter(ValueFromPipelineByPropertyName = $true)] [uint16]$Id, - + [uint16]$Name, - + [object]$Form_Factor, - + [bool]$Enabled, - + [uint16]$MTU, - + [bool]$MGMT_Only, - + [string]$Device, - + [uint16]$Device_Id, - + [uint16]$Type, - + [uint16]$LAG_Id, - + [string]$MAC_Address, - + [switch]$Raw ) - + if ($null -ne $Form_Factor) { $PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor } - + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces')) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } @@ -1507,7 +1507,7 @@ function Get-NetboxDCIMInterface { #region File Get-NetboxDCIMInterfaceConnection.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -1527,30 +1527,30 @@ function Get-NetboxDCIMInterfaceConnection { param ( [uint16]$Limit, - + [uint16]$Offset, - + [uint16]$Id, - + [object]$Connection_Status, - + [uint16]$Site, - + [uint16]$Device, - + [switch]$Raw ) - + if ($null -ne $Connection_Status) { $PSBoundParameters.Connection_Status = ValidateDCIMChoice -ProvidedValue $Connection_Status -InterfaceConnectionStatus } - + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections')) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw' - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } @@ -1558,7 +1558,7 @@ function Get-NetboxDCIMInterfaceConnection { #region File Get-NetboxDCIMPlatform.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -1578,45 +1578,45 @@ function Get-NetboxDCIMPlatform { param ( [uint16]$Limit, - + [uint16]$Offset, - + [Parameter(ParameterSetName = 'ById')] [uint16[]]$Id, - + [string]$Name, - + [string]$Slug, - + [uint16]$Manufacturer_Id, - + [string]$Manufacturer, - + [switch]$Raw ) - + switch ($PSCmdlet.ParameterSetName) { 'ById' { foreach ($PlatformID in $Id) { $Segments = [System.Collections.ArrayList]::new(@('dcim', 'platforms', $PlatformID)) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Raw' - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } - + break } - + default { $Segments = [System.Collections.ArrayList]::new(@('dcim', 'platforms')) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw' - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } } @@ -1626,7 +1626,7 @@ function Get-NetboxDCIMPlatform { #region File Get-NetboxDCIMSite.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 @@ -1648,87 +1648,87 @@ function Get-NetboxDCIMSite { ( [Parameter(ParameterSetName = 'ByID', ValueFromPipelineByPropertyName = $true)] [uint32]$Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Name, - + [Parameter(ParameterSetName = 'Query')] [string]$Query, - + [Parameter(ParameterSetName = 'Query')] [string]$Slug, - + [Parameter(ParameterSetName = 'Query')] [string]$Facility, - + [Parameter(ParameterSetName = 'Query')] [uint32]$ASN, - + [Parameter(ParameterSetName = 'Query')] [decimal]$Latitude, - + [Parameter(ParameterSetName = 'Query')] [decimal]$Longitude, - + [Parameter(ParameterSetName = 'Query')] [string]$Contact_Name, - + [Parameter(ParameterSetName = 'Query')] [string]$Contact_Phone, - + [Parameter(ParameterSetName = 'Query')] [string]$Contact_Email, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Tenant_Group_ID, - + [Parameter(ParameterSetName = 'Query')] [string]$Tenant_Group, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Tenant_ID, - + [Parameter(ParameterSetName = 'Query')] [string]$Tenant, - + [Parameter(ParameterSetName = 'Query')] [string]$Status, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Region_ID, - + [Parameter(ParameterSetName = 'Query')] [string]$Region, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Limit, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Offset, - + [switch]$Raw ) - + switch ($PSCmdlet.ParameterSetName) { 'ById' { foreach ($Site_ID in $ID) { $Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites', $Site_Id)) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id" - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } } - + default { $Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites')) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters - + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $URI -Raw:$Raw } } @@ -1758,12 +1758,12 @@ function Get-NetboxHostname { function Get-NetboxHostPort { [CmdletBinding()] param () - + Write-Verbose "Getting Netbox host port" if ($null -eq $script:NetboxConfig.HostPort) { throw "Netbox host port is not set! You may set it with Set-NetboxHostPort -Port 'https'" } - + $script:NetboxConfig.HostPort } @@ -1774,12 +1774,12 @@ function Get-NetboxHostPort { function Get-NetboxHostScheme { [CmdletBinding()] param () - + Write-Verbose "Getting Netbox host scheme" if ($null -eq $script:NetboxConfig.Hostscheme) { throw "Netbox host sceme is not set! You may set it with Set-NetboxHostScheme -Scheme 'https'" } - + $script:NetboxConfig.HostScheme } @@ -1901,7 +1901,7 @@ function Get-NetboxIPAMAddress { #region File Get-NetboxIPAMAggregate.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -1921,61 +1921,61 @@ function Get-NetboxIPAMAggregate { ( [Parameter(ParameterSetName = 'Query')] [string]$Query, - + [Parameter(ParameterSetName = 'ByID')] [uint16[]]$Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Prefix, - + [Parameter(ParameterSetName = 'Query')] [object]$Family, - + [Parameter(ParameterSetName = 'Query')] [uint16]$RIR_Id, - + [Parameter(ParameterSetName = 'Query')] [string]$RIR, - + [Parameter(ParameterSetName = 'Query')] [datetime]$Date_Added, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Limit, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Offset, - + [switch]$Raw ) - + # if ($null -ne $Family) { # $PSBoundParameters.Family = ValidateIPAMChoice -ProvidedValue $Family -AggregateFamily # } - + switch ($PSCmdlet.ParameterSetName) { 'ById' { foreach ($IP_ID in $Id) { $Segments = [System.Collections.ArrayList]::new(@('ipam', 'aggregates', $IP_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(@('ipam', 'aggregates')) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $uri -Raw:$Raw - + break } } @@ -2063,7 +2063,7 @@ function Get-NetboxIPAMAvailableIP { #region File Get-NetboxIPAMPrefix.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -2081,189 +2081,189 @@ function Get-NetboxIPAMPrefix { <# .SYNOPSIS A brief description of the Get-NetboxIPAMPrefix function. - + .DESCRIPTION A detailed description of the Get-NetboxIPAMPrefix function. - + .PARAMETER Query A description of the Query parameter. - + .PARAMETER Id A description of the Id parameter. - + .PARAMETER Limit A description of the Limit parameter. - + .PARAMETER Offset A description of the Offset parameter. - + .PARAMETER Family A description of the Family parameter. - + .PARAMETER Is_Pool A description of the Is_Pool parameter. - + .PARAMETER Within Should be a CIDR notation prefix such as '10.0.0.0/16' - + .PARAMETER Within_Include Should be a CIDR notation prefix such as '10.0.0.0/16' - + .PARAMETER Contains A description of the Contains parameter. - + .PARAMETER Mask_Length CIDR mask length value - + .PARAMETER VRF A description of the VRF parameter. - + .PARAMETER VRF_Id A description of the VRF_Id parameter. - + .PARAMETER Tenant A description of the Tenant parameter. - + .PARAMETER Tenant_Id A description of the Tenant_Id parameter. - + .PARAMETER Site A description of the Site parameter. - + .PARAMETER Site_Id A description of the Site_Id parameter. - + .PARAMETER Vlan_VId A description of the Vlan_VId parameter. - + .PARAMETER Vlan_Id A description of the Vlan_Id parameter. - + .PARAMETER Status A description of the Status parameter. - + .PARAMETER Role A description of the Role parameter. - + .PARAMETER Role_Id A description of the Role_Id parameter. - + .PARAMETER Raw A description of the Raw parameter. - + .EXAMPLE PS C:\> Get-NetboxIPAMPrefix - + .NOTES Additional information about the function. #> - + [CmdletBinding(DefaultParameterSetName = 'Query')] param ( [Parameter(ParameterSetName = 'Query', Position = 0)] [string]$Prefix, - + [Parameter(ParameterSetName = 'Query')] [string]$Query, - + [Parameter(ParameterSetName = 'ByID')] [uint32[]]$Id, - + [Parameter(ParameterSetName = 'Query')] [object]$Family, - + [Parameter(ParameterSetName = 'Query')] [boolean]$Is_Pool, - + [Parameter(ParameterSetName = 'Query')] [string]$Within, - + [Parameter(ParameterSetName = 'Query')] [string]$Within_Include, - + [Parameter(ParameterSetName = 'Query')] [string]$Contains, - + [Parameter(ParameterSetName = 'Query')] [ValidateRange(0, 127)] [byte]$Mask_Length, - + [Parameter(ParameterSetName = 'Query')] [string]$VRF, - + [Parameter(ParameterSetName = 'Query')] [uint32]$VRF_Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Tenant, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Tenant_Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Site, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Site_Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Vlan_VId, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Vlan_Id, - + [Parameter(ParameterSetName = 'Query')] [object]$Status, - + [Parameter(ParameterSetName = 'Query')] [string]$Role, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Role_Id, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Limit, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Offset, - + [switch]$Raw ) - + # if ($null -ne $Family) { # $PSBoundParameters.Family = ValidateIPAMChoice -ProvidedValue $Family -PrefixFamily # } - # + # # if ($null -ne $Status) { # $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -PrefixStatus # } - + switch ($PSCmdlet.ParameterSetName) { 'ById' { foreach ($Prefix_ID in $Id) { $Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes', $Prefix_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(@('ipam', 'prefixes')) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $uri -Raw:$Raw - + break } } @@ -2278,93 +2278,93 @@ function Get-NetboxIPAMRole { <# .SYNOPSIS Get IPAM Prefix/VLAN roles - + .DESCRIPTION A role indicates the function of a prefix or VLAN. For example, you might define Data, Voice, and Security roles. Generally, a prefix will be assigned the same functional role as the VLAN to which it is assigned (if any). - + .PARAMETER Id Unique ID - + .PARAMETER Query Search query - + .PARAMETER Name Role name - + .PARAMETER Slug Role URL slug - + .PARAMETER Brief Brief format - + .PARAMETER Limit Result limit - + .PARAMETER Offset Result offset - + .PARAMETER Raw A description of the Raw parameter. - + .EXAMPLE PS C:\> Get-NetboxIPAMRole - + .NOTES Additional information about the function. #> - + [CmdletBinding()] param ( [Parameter(ParameterSetName = 'Query', Position = 0)] [string]$Name, - + [Parameter(ParameterSetName = 'Query')] [string]$Query, - + [Parameter(ParameterSetName = 'ByID')] [uint32[]]$Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Slug, - + [Parameter(ParameterSetName = 'Query')] [switch]$Brief, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Limit, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Offset, - + [switch]$Raw ) - + switch ($PSCmdlet.ParameterSetName) { 'ById' { foreach ($Role_ID in $Id) { $Segments = [System.Collections.ArrayList]::new(@('ipam', 'roles', $Role_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(@('ipam', 'roles')) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $uri -Raw:$Raw - + break } } @@ -2374,7 +2374,7 @@ function Get-NetboxIPAMRole { #region File Get-NetboxIPAMVLAN.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -2396,89 +2396,89 @@ function Get-NetboxIPAMVLAN { Position = 0)] [ValidateRange(1, 4096)] [uint16]$VID, - + [Parameter(ParameterSetName = 'ByID')] [uint32[]]$Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Query, - + [Parameter(ParameterSetName = 'Query')] [string]$Name, - + [Parameter(ParameterSetName = 'Query')] [string]$Tenant, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Tenant_Id, - + [Parameter(ParameterSetName = 'Query')] [string]$TenantGroup, - + [Parameter(ParameterSetName = 'Query')] [uint32]$TenantGroup_Id, - + [Parameter(ParameterSetName = 'Query')] [object]$Status, - + [Parameter(ParameterSetName = 'Query')] [string]$Region, - + [Parameter(ParameterSetName = 'Query')] [string]$Site, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Site_Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Group, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Group_Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Role, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Role_Id, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Limit, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Offset, - + [switch]$Raw ) - + # if ($null -ne $Status) { # $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus # } - + switch ($PSCmdlet.ParameterSetName) { 'ById' { foreach ($VLAN_ID in $Id) { $Segments = [System.Collections.ArrayList]::new(@('ipam', 'vlans', $VLAN_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(@('ipam', 'vlans')) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $uri -Raw:$Raw - + break } } @@ -2492,7 +2492,7 @@ function Get-NetboxIPAMVLAN { #region File Get-NetboxTenant.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -2510,105 +2510,105 @@ function Get-NetboxTenant { <# .SYNOPSIS Get a tenent from Netbox - + .DESCRIPTION A detailed description of the Get-NetboxTenant function. - + .PARAMETER Name The specific name of the tenant. Must match exactly as is defined in Netbox - + .PARAMETER Id The database ID of the tenant - + .PARAMETER Query A standard search query that will match one or more tenants. - + .PARAMETER Slug The specific slug of the tenant. Must match exactly as is defined in Netbox - + .PARAMETER Group The specific group as defined in Netbox. - + .PARAMETER GroupID The database ID of the group in Netbox - + .PARAMETER CustomFields Hashtable in the format @{"field_name" = "value"} to search - + .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-NetboxTenant - + .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]$Group, - + [Parameter(ParameterSetName = 'Query')] [uint16]$GroupID, - + [Parameter(ParameterSetName = 'Query')] [hashtable]$CustomFields, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Limit, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Offset, - + [switch]$Raw ) - + switch ($PSCmdlet.ParameterSetName) { 'ById' { foreach ($Tenant_ID in $Id) { $Segments = [System.Collections.ArrayList]::new(@('tenancy', 'tenants', $Tenant_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', 'tenants')) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $uri -Raw:$Raw - + break } } @@ -2656,7 +2656,7 @@ function Get-NetboxVersion { #region File Get-NetboxVirtualizationCluster.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -2674,88 +2674,88 @@ function Get-NetboxVirtualizationCluster { <# .SYNOPSIS Obtains virtualization clusters from Netbox. - + .DESCRIPTION Obtains one or more virtualization clusters based on provided filters. - + .PARAMETER Limit Number of results to return per page - + .PARAMETER Offset The initial index from which to return the results - + .PARAMETER Query A general query used to search for a cluster - + .PARAMETER Name Name of the cluster - + .PARAMETER Id Database ID(s) of the cluster - + .PARAMETER Group String value of the cluster group. - + .PARAMETER Group_Id Database ID of the cluster group. - + .PARAMETER Type String value of the Cluster type. - + .PARAMETER Type_Id Database ID of the cluster type. - + .PARAMETER Site String value of the site. - + .PARAMETER Site_Id Database ID of the site. - + .PARAMETER Raw A description of the Raw parameter. - + .EXAMPLE PS C:\> Get-NetboxVirtualizationCluster - + .NOTES Additional information about the function. #> - + [CmdletBinding()] param ( [string]$Name, - + [Alias('q')] [string]$Query, - + [uint16[]]$Id, - + [string]$Group, - + [uint16]$Group_Id, - + [string]$Type, - + [uint16]$Type_Id, - + [string]$Site, - + [uint16]$Site_Id, - + [uint16]$Limit, - + [uint16]$Offset, - + [switch]$Raw ) - + $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'clusters')) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $uri -Raw:$Raw } @@ -2763,7 +2763,7 @@ function Get-NetboxVirtualizationCluster { #region File Get-NetboxVirtualizationClusterGroup.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -2782,28 +2782,28 @@ function Get-NetboxVirtualizationClusterGroup { param ( [string]$Name, - + [string]$Slug, - + [string]$Description, - + [string]$Query, - + [uint32[]]$Id, - + [uint16]$Limit, - + [uint16]$Offset, - + [switch]$Raw ) - + $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'cluster-groups')) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $uri -Raw:$Raw } @@ -2811,7 +2811,7 @@ function Get-NetboxVirtualizationClusterGroup { #region File Get-NetboxVirtualMachine.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -2829,141 +2829,141 @@ function Get-NetboxVirtualMachine { <# .SYNOPSIS Obtains virtual machines from Netbox. - + .DESCRIPTION Obtains one or more virtual machines based on provided filters. - + .PARAMETER Limit Number of results to return per page - + .PARAMETER Offset The initial index from which to return the results - + .PARAMETER Query A general query used to search for a VM - + .PARAMETER Name Name of the VM - + .PARAMETER Id Database ID of the VM - + .PARAMETER Status Status of the VM - + .PARAMETER Tenant String value of tenant - + .PARAMETER Tenant_ID Database ID of the tenant. - + .PARAMETER Platform String value of the platform - + .PARAMETER Platform_ID Database ID of the platform - + .PARAMETER Cluster_Group String value of the cluster group. - + .PARAMETER Cluster_Group_Id Database ID of the cluster group. - + .PARAMETER Cluster_Type String value of the Cluster type. - + .PARAMETER Cluster_Type_Id Database ID of the cluster type. - + .PARAMETER Cluster_Id Database ID of the cluster. - + .PARAMETER Site String value of the site. - + .PARAMETER Site_Id Database ID of the site. - + .PARAMETER Role String value of the role. - + .PARAMETER Role_Id Database ID of the role. - + .PARAMETER Raw A description of the Raw parameter. - + .PARAMETER TenantID Database ID of tenant - + .PARAMETER PlatformID Database ID of the platform - + .PARAMETER id__in Database IDs of VMs - + .EXAMPLE PS C:\> Get-NetboxVirtualMachine - + .NOTES Additional information about the function. #> - + [CmdletBinding()] param ( [Alias('q')] [string]$Query, - + [string]$Name, - + [uint16[]]$Id, - + [object]$Status, - + [string]$Tenant, - + [uint16]$Tenant_ID, - + [string]$Platform, - + [uint16]$Platform_ID, - + [string]$Cluster_Group, - + [uint16]$Cluster_Group_Id, - + [string]$Cluster_Type, - + [uint16]$Cluster_Type_Id, - + [uint16]$Cluster_Id, - + [string]$Site, - + [uint16]$Site_Id, - + [string]$Role, - + [uint16]$Role_Id, - + [uint16]$Limit, - + [uint16]$Offset, - + [switch]$Raw ) - + if ($null -ne $Status) { $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus } - + $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines')) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $uri -Raw:$Raw } @@ -2971,7 +2971,7 @@ function Get-NetboxVirtualMachine { #region File Get-NetboxVirtualMachineInterface.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -2989,80 +2989,80 @@ function Get-NetboxVirtualMachineInterface { <# .SYNOPSIS Gets VM interfaces - + .DESCRIPTION Obtains the interface objects for one or more VMs - + .PARAMETER Limit Number of results to return per page. - + .PARAMETER Offset The initial index from which to return the results. - + .PARAMETER Id Database ID of the interface - + .PARAMETER Name Name of the interface - + .PARAMETER Enabled True/False if the interface is enabled - + .PARAMETER MTU Maximum Transmission Unit size. Generally 1500 or 9000 - + .PARAMETER Virtual_Machine_Id ID of the virtual machine to which the interface(s) are assigned. - + .PARAMETER Virtual_Machine Name of the virtual machine to get interfaces - + .PARAMETER MAC_Address MAC address assigned to the interface - + .PARAMETER Raw A description of the Raw parameter. - + .EXAMPLE PS C:\> Get-NetboxVirtualMachineInterface - + .NOTES Additional information about the function. #> - + [CmdletBinding()] param ( [Parameter(ValueFromPipeline = $true)] [uint16]$Id, - + [string]$Name, - + [string]$Query, - + [boolean]$Enabled, - + [uint16]$MTU, - + [uint16]$Virtual_Machine_Id, - + [string]$Virtual_Machine, - + [string]$MAC_Address, - + [uint16]$Limit, - + [uint16]$Offset, - + [switch]$Raw ) - + $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces')) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $uri -Raw:$Raw } @@ -3182,7 +3182,7 @@ function InvokeNetboxRequest { #region File New-NetboxCircuit.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 @@ -3206,45 +3206,45 @@ function New-NetboxCircuit { [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [string]$CID, - + [Parameter(Mandatory = $true)] [uint32]$Provider, - + [Parameter(Mandatory = $true)] [uint32]$Type, - + #[ValidateSet('Active', 'Planned', 'Provisioning', 'Offline', 'Deprovisioning', 'Decommissioned ')] [uint16]$Status = 'Active', - + [string]$Description, - + [uint32]$Tenant, - + [string]$Termination_A, - + [datetime]$Install_Date, - + [string]$Termination_Z, - + [ValidateRange(0, 2147483647)] [uint32]$Commit_Rate, - + [string]$Comments, - + [hashtable]$Custom_Fields, - + [switch]$Force, - + [switch]$Raw ) - + $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits')) $Method = 'POST' - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - + $URI = BuildNewURI -Segments $URIComponents.Segments - + if ($Force -or $PSCmdlet.ShouldProcess($CID, 'Create new circuit')) { InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw } @@ -3254,7 +3254,7 @@ function New-NetboxCircuit { #region File New-NetboxDCIMDevice.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -3276,72 +3276,72 @@ function New-NetboxDCIMDevice { ( [Parameter(Mandatory = $true)] [string]$Name, - + [Parameter(Mandatory = $true)] [object]$Device_Role, - + [Parameter(Mandatory = $true)] [object]$Device_Type, - + [Parameter(Mandatory = $true)] [uint16]$Site, - + [object]$Status = 'Active', - + [uint16]$Platform, - + [uint16]$Tenant, - + [uint16]$Cluster, - + [uint16]$Rack, - + [uint16]$Position, - + [object]$Face, - + [string]$Serial, - + [string]$Asset_Tag, - + [uint16]$Virtual_Chassis, - + [uint16]$VC_Priority, - + [uint16]$VC_Position, - + [uint16]$Primary_IP4, - + [uint16]$Primary_IP6, - + [string]$Comments, - + [hashtable]$Custom_Fields ) #endregion Parameters - + # if ($null -ne $Device_Role) { # # Validate device role? # } -# + # if ($null -ne $Device_Type) { # # Validate device type? # } -# + # if ($null -ne $Status) { # $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus # } -# + # if ($null -ne $Face) { # $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace # } - + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices')) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters - + $URI = BuildNewURI -Segments $URIComponents.Segments - + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST } @@ -3480,7 +3480,7 @@ function New-NetboxIPAMAddress { #region File New-NetboxIPAMPrefix.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -3500,43 +3500,43 @@ function New-NetboxIPAMPrefix { ( [Parameter(Mandatory = $true)] [string]$Prefix, - + [object]$Status = 'Active', - + [uint16]$Tenant, - + [object]$Role, - + [bool]$IsPool, - + [string]$Description, - + [uint16]$Site, - + [uint16]$VRF, - + [uint16]$VLAN, - + [hashtable]$Custom_Fields, - + [switch]$Raw ) - + # $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -PrefixStatus - + <# # As of 2018/10/18, this does not appear to be a validated IPAM choice if ($null -ne $Role) { $PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -PrefixRole } #> - + $segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes')) - + $URIComponents = BuildURIComponents -URISegments $segments -ParametersDictionary $PSBoundParameters - + $URI = BuildNewURI -Segments $URIComponents.Segments - + InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw } @@ -3548,79 +3548,79 @@ function New-NetboxIPAMVLAN { <# .SYNOPSIS Create a new VLAN - + .DESCRIPTION Create a new VLAN in Netbox with a status of Active by default. - + .PARAMETER VID The VLAN ID. - + .PARAMETER Name The name of the VLAN. - + .PARAMETER Status Status of the VLAN. Defaults to Active - + .PARAMETER Tenant Tenant ID - + .PARAMETER Role Role such as anycast, loopback, etc... Defaults to nothing - + .PARAMETER Description Description of IP address - + .PARAMETER Custom_Fields Custom field hash table. Will be validated by the API service - + .PARAMETER Raw Return raw results from API service - + .PARAMETER Address IP address in CIDR notation: 192.168.1.1/24 - + .EXAMPLE PS C:\> Create-NetboxIPAMAddress - + .NOTES Additional information about the function. #> - + [CmdletBinding()] [OutputType([pscustomobject])] param ( [Parameter(Mandatory = $true)] [uint16]$VID, - + [Parameter(Mandatory = $true)] [string]$Name, - + [object]$Status = 'Active', - + [uint16]$Tenant, - + [object]$Role, - + [string]$Description, - + [hashtable]$Custom_Fields, - + [switch]$Raw ) - + # $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus -# + # if ($null -ne $Role) { # $PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole # } - + $segments = [System.Collections.ArrayList]::new(@('ipam', 'vlans')) - + $URIComponents = BuildURIComponents -URISegments $segments -ParametersDictionary $PSBoundParameters - + $URI = BuildNewURI -Segments $URIComponents.Segments - + InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw } @@ -3628,7 +3628,7 @@ function New-NetboxIPAMVLAN { #region File New-NetboxVirtualMachine.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -3649,48 +3649,48 @@ function New-NetboxVirtualMachine { ( [Parameter(Mandatory = $true)] [string]$Name, - + [Parameter(Mandatory = $true)] [uint16]$Cluster, - + [uint16]$Tenant, - + [object]$Status = 'Active', - + [uint16]$Role, - + [uint16]$Platform, - + [uint16]$vCPUs, - + [uint16]$Memory, - + [uint16]$Disk, - + [uint16]$Primary_IP4, - + [uint16]$Primary_IP6, - + [hashtable]$Custom_Fields, - + [string]$Comments ) - + # $ModelDefinition = $script:NetboxConfig.APIDefinition.definitions.WritableVirtualMachineWithConfigContext -# + # # Validate the status against the APIDefinition # if ($ModelDefinition.properties.status.enum -inotcontains $Status) { # throw ("Invalid value [] for Status. Must be one of []" -f $Status, ($ModelDefinition.properties.status.enum -join ', ')) # } -# + #$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus - + $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines')) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - + $URI = BuildNewURI -Segments $URIComponents.Segments - + InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters } @@ -3702,7 +3702,7 @@ function New-NetboxVirtualMachine { #region File Remove-NetboxDCIMDevice.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -3720,23 +3720,23 @@ function Remove-NetboxDCIMDevice { <# .SYNOPSIS Delete a device - + .DESCRIPTION Deletes a device from Netbox by ID - + .PARAMETER Id Database ID of the device - + .PARAMETER Force Force deletion without any prompts - + .EXAMPLE PS C:\> Remove-NetboxDCIMDevice -Id $value1 - + .NOTES Additional information about the function. #> - + [CmdletBinding(ConfirmImpact = 'High', SupportsShouldProcess = $true)] param @@ -3744,30 +3744,30 @@ function Remove-NetboxDCIMDevice { [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [uint16[]]$Id, - + [switch]$Force ) - + begin { - + } - + process { foreach ($DeviceID in $Id) { $CurrentDevice = Get-NetboxDCIMDevice -Id $DeviceID -ErrorAction Stop - + if ($Force -or $pscmdlet.ShouldProcess("Name: $($CurrentDevice.Name) | ID: $($CurrentDevice.Id)", "Remove")) { $Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices', $CurrentDevice.Id)) - + $URI = BuildNewURI -Segments $Segments - + InvokeNetboxRequest -URI $URI -Method DELETE } } } - + end { - + } } @@ -3775,7 +3775,7 @@ function Remove-NetboxDCIMDevice { #region File Remove-NetboxDCIMInterface.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -3793,23 +3793,23 @@ function Remove-NetboxDCIMInterface { <# .SYNOPSIS Removes an interface - + .DESCRIPTION Removes an interface by ID from a device - + .PARAMETER Id A description of the Id parameter. - + .PARAMETER Force A description of the Force parameter. - + .EXAMPLE PS C:\> Remove-NetboxDCIMInterface -Id $value1 - + .NOTES Additional information about the function. #> - + [CmdletBinding(ConfirmImpact = 'High', SupportsShouldProcess = $true)] param @@ -3817,30 +3817,30 @@ function Remove-NetboxDCIMInterface { [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [uint16[]]$Id, - + [switch]$Force ) - + begin { - + } - + process { foreach ($InterfaceId in $Id) { $CurrentInterface = Get-NetboxDCIMInterface -Id $InterfaceId -ErrorAction Stop - + if ($Force -or $pscmdlet.ShouldProcess("Name: $($CurrentInterface.Name) | ID: $($CurrentInterface.Id)", "Remove")) { $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces', $CurrentInterface.Id)) - + $URI = BuildNewURI -Segments $Segments - + InvokeNetboxRequest -URI $URI -Method DELETE } } } - + end { - + } } @@ -3848,7 +3848,7 @@ function Remove-NetboxDCIMInterface { #region File Remove-NetboxDCIMInterfaceConnection.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -3871,32 +3871,32 @@ function Remove-NetboxDCIMInterfaceConnection { [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [uint16[]]$Id, - + [switch]$Force ) - + begin { - + } - + process { foreach ($ConnectionID in $Id) { $CurrentConnection = Get-NetboxDCIMInterfaceConnection -Id $ConnectionID -ErrorAction Stop - + if ($Force -or $pscmdlet.ShouldProcess("Connection ID $($ConnectionID.Id)", "REMOVE")) { $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections', $CurrentConnection.Id)) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force' - + $URI = BuildNewURI -Segments $URIComponents.Segments - + InvokeNetboxRequest -URI $URI -Method DELETE } } } - + end { - + } } @@ -3968,7 +3968,7 @@ function Remove-NetboxIPAMAddress { #region File Remove-NetboxVirtualMachine.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -3986,23 +3986,23 @@ function Remove-NetboxVirtualMachine { <# .SYNOPSIS Delete a virtual machine - + .DESCRIPTION Deletes a virtual machine from Netbox by ID - + .PARAMETER Id Database ID of the virtual machine - + .PARAMETER Force Force deletion without any prompts - + .EXAMPLE PS C:\> Remove-NetboxVirtualMachine -Id $value1 - + .NOTES Additional information about the function. #> - + [CmdletBinding(ConfirmImpact = 'High', SupportsShouldProcess = $true)] param @@ -4010,30 +4010,30 @@ function Remove-NetboxVirtualMachine { [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [uint16[]]$Id, - + [switch]$Force ) - + begin { - + } - + process { foreach ($VMId in $Id) { $CurrentVM = Get-NetboxVirtualMachine -Id $VMId -ErrorAction Stop - + if ($Force -or $pscmdlet.ShouldProcess("$($CurrentVM.Name)/$($CurrentVM.Id)", "Remove")) { $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines', $CurrentVM.Id)) - + $URI = BuildNewURI -Segments $Segments - + InvokeNetboxRequest -URI $URI -Method DELETE } } } - + end { - + } } @@ -4091,7 +4091,7 @@ function Set-NetboxCredential { #region File Set-NetboxDCIMDevice.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -4112,78 +4112,78 @@ function Set-NetboxDCIMDevice { [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [uint16[]]$Id, - + [string]$Name, - + [object]$Device_Role, - + [object]$Device_Type, - + [uint16]$Site, - + [object]$Status, - + [uint16]$Platform, - + [uint16]$Tenant, - + [uint16]$Cluster, - + [uint16]$Rack, - + [uint16]$Position, - + [object]$Face, - + [string]$Serial, - + [string]$Asset_Tag, - + [uint16]$Virtual_Chassis, - + [uint16]$VC_Priority, - + [uint16]$VC_Position, - + [uint16]$Primary_IP4, - + [uint16]$Primary_IP6, - + [string]$Comments, - + [hashtable]$Custom_Fields, - + [switch]$Force ) - + begin { # if ($null -ne $Status) { # $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus # } -# + # if ($null -ne $Face) { # $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace # } } - + process { foreach ($DeviceID in $Id) { $CurrentDevice = Get-NetboxDCIMDevice -Id $DeviceID -ErrorAction Stop - + if ($Force -or $pscmdlet.ShouldProcess("$($CurrentDevice.Name)", "Set")) { $Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices', $CurrentDevice.Id)) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force' - + $URI = BuildNewURI -Segments $URIComponents.Segments - + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH } } } - + end { - + } } @@ -4191,7 +4191,7 @@ function Set-NetboxDCIMDevice { #region File Set-NetboxDCIMInterface.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -4213,80 +4213,80 @@ function Set-NetboxDCIMInterface { [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [uint16[]]$Id, - + [uint16]$Device, - + [string]$Name, - + [bool]$Enabled, - + [object]$Form_Factor, - + [uint16]$MTU, - + [string]$MAC_Address, - + [bool]$MGMT_Only, - + [uint16]$LAG, - + [string]$Description, - + [ValidateSet('Access', 'Tagged', 'Tagged All', '100', '200', '300', IgnoreCase = $true)] [string]$Mode, - + [ValidateRange(1, 4094)] [uint16]$Untagged_VLAN, - + [ValidateRange(1, 4094)] [uint16[]]$Tagged_VLANs ) - + begin { # if ($null -ne $Form_Factor) { # $PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor # } - + if (-not [System.String]::IsNullOrWhiteSpace($Mode)) { $PSBoundParameters.Mode = switch ($Mode) { 'Access' { 100 break } - + 'Tagged' { 200 break } - + 'Tagged All' { 300 break } - + default { $_ } } } } - + process { foreach ($InterfaceId in $Id) { $CurrentInterface = Get-NetboxDCIMInterface -Id $InterfaceId -ErrorAction Stop - + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces', $CurrentInterface.Id)) - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id' - + $URI = BuildNewURI -Segments $Segments - + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH } } - + end { - + } } @@ -4294,7 +4294,7 @@ function Set-NetboxDCIMInterface { #region File Set-NetboxDCIMInterfaceConnection.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -4312,32 +4312,32 @@ function Set-NetboxDCIMInterfaceConnection { <# .SYNOPSIS Update an interface connection - + .DESCRIPTION Update an interface connection - + .PARAMETER Id A description of the Id parameter. - + .PARAMETER Connection_Status A description of the Connection_Status parameter. - + .PARAMETER Interface_A A description of the Interface_A parameter. - + .PARAMETER Interface_B A description of the Interface_B parameter. - + .PARAMETER Force A description of the Force parameter. - + .EXAMPLE PS C:\> Set-NetboxDCIMInterfaceConnection -Id $value1 - + .NOTES Additional information about the function. #> - + [CmdletBinding(ConfirmImpact = 'Medium', SupportsShouldProcess = $true)] param @@ -4345,45 +4345,45 @@ function Set-NetboxDCIMInterfaceConnection { [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [uint16[]]$Id, - + [object]$Connection_Status, - + [uint16]$Interface_A, - + [uint16]$Interface_B, - + [switch]$Force ) - + begin { # if ($null -ne $Connection_Status) { # $PSBoundParameters.Connection_Status = ValidateDCIMChoice -ProvidedValue $Connection_Status -InterfaceConnectionStatus # } - + if ((@($ID).Count -gt 1) -and ($Interface_A -or $Interface_B)) { throw "Cannot set multiple connections to the same interface" } } - + process { foreach ($ConnectionID in $Id) { $CurrentConnection = Get-NetboxDCIMInterfaceConnection -Id $ConnectionID -ErrorAction Stop - + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections', $CurrentConnection.Id)) - + if ($Force -or $pscmdlet.ShouldProcess("Connection ID $($CurrentConnection.Id)", "Set")) { - + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force' - + $URI = BuildNewURI -Segments $URIComponents.Segments - + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH } } } - + end { - + } } @@ -4420,7 +4420,7 @@ function Set-NetboxHostPort { [Parameter(Mandatory = $true)] [uint16]$Port ) - + if ($PSCmdlet.ShouldProcess('Netbox Port', 'Set')) { $script:NetboxConfig.HostPort = $Port $script:NetboxConfig.HostPort @@ -4441,12 +4441,12 @@ function Set-NetboxHostScheme { [ValidateSet('https', 'http', IgnoreCase = $true)] [string]$Scheme = 'https' ) - + if ($PSCmdlet.ShouldProcess('Netbox Host Scheme', 'Set')) { if ($Scheme -eq 'http') { Write-Warning "Connecting via non-secure HTTP is not-recommended" } - + $script:NetboxConfig.HostScheme = $Scheme $script:NetboxConfig.HostScheme } @@ -4576,7 +4576,7 @@ function Set-NetboxIPAMAddress { #region File Set-NetboxIPAMPrefix.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2021 v5.8.186 @@ -4598,39 +4598,39 @@ function Set-NetboxIPAMPrefix { [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [uint16[]]$Id, - + [string]$Prefix, - + [string]$Status, - + [uint16]$Tenant, - + [uint16]$Site, - + [uint16]$VRF, - + [uint16]$VLAN, - + [object]$Role, - + [hashtable]$Custom_Fields, - + [string]$Description, - + [switch]$Is_Pool, - + [switch]$Force ) - + begin { # Write-Verbose "Validating enum properties" # $Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses', 0)) $Method = 'PATCH' - # + # # # Value validation # $ModelDefinition = GetModelDefinitionFromURIPath -Segments $Segments -Method $Method # $EnumProperties = GetModelEnumProperties -ModelDefinition $ModelDefinition - # + # # foreach ($Property in $EnumProperties.Keys) { # if ($PSBoundParameters.ContainsKey($Property)) { # Write-Verbose "Validating property [$Property] with value [$($PSBoundParameters.$Property)]" @@ -4639,22 +4639,22 @@ function Set-NetboxIPAMPrefix { # Write-Verbose "User did not provide a value for [$Property]" # } # } - # + # # Write-Verbose "Finished enum validation" } - + process { foreach ($PrefixId in $Id) { $Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes', $PrefixId)) - + Write-Verbose "Obtaining Prefix from ID $PrefixId" $CurrentPrefix = Get-NetboxIPAMPrefix -Id $PrefixId -ErrorAction Stop - + if ($Force -or $PSCmdlet.ShouldProcess($CurrentPrefix.Prefix, 'Set')) { $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force' - + $URI = BuildNewURI -Segments $URIComponents.Segments - + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method $Method } } @@ -4719,7 +4719,7 @@ Function Set-NetboxUntrustedSSL { #region File Set-NetboxVirtualMachine.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -4741,53 +4741,53 @@ function Set-NetboxVirtualMachine { [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [uint16]$Id, - + [string]$Name, - + [uint16]$Role, - + [uint16]$Cluster, - + [object]$Status, - + [uint16]$Platform, - + [uint16]$Primary_IP4, - + [uint16]$Primary_IP6, - + [byte]$VCPUs, - + [uint16]$Memory, - + [uint16]$Disk, - + [uint16]$Tenant, - + [string]$Comments, - + [hashtable]$Custom_Fields, - + [switch]$Force ) - + # if ($null -ne $Status) { # $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus # } -# + $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines', $Id)) - + Write-Verbose "Obtaining VM from ID $Id" - + #$CurrentVM = Get-NetboxVirtualMachine -Id $Id -ErrorAction Stop - + Write-Verbose "Finished obtaining VM" - + if ($Force -or $pscmdlet.ShouldProcess($ID, "Set properties on VM ID")) { $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force' - + $URI = BuildNewURI -Segments $URIComponents.Segments - + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH } } @@ -4796,7 +4796,7 @@ function Set-NetboxVirtualMachine { #region File Set-NetboxVirtualMachineInterface.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -4819,46 +4819,46 @@ function Set-NetboxVirtualMachineInterface { [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [uint16[]]$Id, - + [string]$Name, - + [string]$MAC_Address, - + [uint16]$MTU, - + [string]$Description, - + [boolean]$Enabled, - + [uint16]$Virtual_Machine, - + [switch]$Force ) - + begin { - + } - + process { foreach ($VMI_ID in $Id) { Write-Verbose "Obtaining VM Interface..." $CurrentVMI = Get-NetboxVirtualMachineInterface -Id $VMI_ID -ErrorAction Stop Write-Verbose "Finished obtaining VM Interface" - + $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces', $CurrentVMI.Id)) - + if ($Force -or $pscmdlet.ShouldProcess("Interface $($CurrentVMI.Id) on VM $($CurrentVMI.Virtual_Machine.Name)", "Set")) { $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force' - + $URI = BuildNewURI -Segments $URIComponents.Segments - + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH } } } - + end { - + } } @@ -4891,7 +4891,7 @@ function SetupNetboxConfigVariable { #region File Tenancy.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.152 @@ -4932,7 +4932,7 @@ function SetupNetboxConfigVariable { #region File ThrowNetboxRESTError.ps1 -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 @@ -4948,12 +4948,12 @@ function SetupNetboxConfigVariable { function ThrowNetboxRESTError { $uriSegments = [System.Collections.ArrayList]::new(@('fake', 'url')) - + $URIParameters = @{ } - + $uri = BuildNewURI -Segments $uriSegments -Parameters $URIParameters - + InvokeNetboxRequest -URI $uri -Raw } diff --git a/Tests/DCIM.Devices.Tests.ps1 b/Tests/DCIM.Devices.Tests.ps1 index 8a9e22f..5af9b8e 100644 --- a/Tests/DCIM.Devices.Tests.ps1 +++ b/Tests/DCIM.Devices.Tests.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.152 @@ -24,7 +24,7 @@ Describe -Name "DCIM Devices Tests" -Tag 'DCIM', 'Devices' -Fixture { Mock -CommandName 'CheckNetboxIsConnected' -Verifiable -ModuleName 'NetboxPS' -MockWith { return $true } - + Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith { # Return a hashtable of the items we would normally pass to Invoke-RestMethod return [ordered]@{ @@ -36,375 +36,375 @@ Describe -Name "DCIM Devices Tests" -Tag 'DCIM', 'Devices' -Fixture { 'Body' = $Body } } - + Mock -CommandName 'Get-NetboxCredential' -Verifiable -ModuleName 'NetboxPS' -MockWith { return [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force)) } - + Mock -CommandName 'Get-NetboxHostname' -Verifiable -ModuleName 'NetboxPS' -MockWith { return 'netbox.domain.com' } - + InModuleScope -ModuleName 'NetboxPS' -ScriptBlock { $script:NetboxConfig.Choices.DCIM = (Get-Content "$PSScriptRoot\DCIMChoices.json" -ErrorAction Stop | ConvertFrom-Json) - + Context -Name "Get-NetboxDCIMDevice" -Fixture { It "Should request the default number of devices" { $Result = Get-NetboxDCIMDevice - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with a limit and offset" { $Result = Get-NetboxDCIMDevice -Limit 10 -Offset 100 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/?offset=100&limit=10' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with a query" { $Result = Get-NetboxDCIMDevice -Query 'testdevice' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/?q=testdevice' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with an escaped query" { $Result = Get-NetboxDCIMDevice -Query 'test device' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/?q=test+device' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with a name" { $Result = Get-NetboxDCIMDevice -Name 'testdevice' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/?name=testdevice' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with a single ID" { $Result = Get-NetboxDCIMDevice -Id 10 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/10/' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request a device by ID from the pipeline" { $Result = [pscustomobject]@{ 'id' = 10 } | Get-NetboxDCIMDevice - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/10/' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with multiple IDs" { $Result = Get-NetboxDCIMDevice -Id 10, 12, 15 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/?id__in=10,12,15' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request a status" { $Result = Get-NetboxDCIMDevice -Status 'Active' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/?status=1' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should throw for an invalid status" { { Get-NetboxDCIMDevice -Status 'Fake' } | Should -Throw } - + It "Should request devices that are a PDU" { $Result = Get-NetboxDCIMDevice -Is_PDU $True - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/devices/?is_pdu=True' $Result.Headers.Keys.Count | Should -BeExactly 1 } } - + Context -Name "Get-NetboxDCIMDeviceType" -Fixture { It "Should request the default number of devices types" { $Result = Get-NetboxDCIMDeviceType - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with a limit and offset" { $Result = Get-NetboxDCIMDeviceType -Limit 10 -Offset 100 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/?offset=100&limit=10' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with a query" { $Result = Get-NetboxDCIMDeviceType -Query 'testdevice' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/?q=testdevice' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with an escaped query" { $Result = Get-NetboxDCIMDeviceType -Query 'test device' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/?q=test+device' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with a slug" { $Result = Get-NetboxDCIMDeviceType -Slug 'testdevice' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/?slug=testdevice' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with a single ID" { $Result = Get-NetboxDCIMDeviceType -Id 10 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/10/' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with multiple IDs" { $Result = Get-NetboxDCIMDeviceType -Id 10, 12, 15 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/?id__in=10,12,15' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request a device type that is PDU" { $Result = Get-NetboxDCIMDeviceType -Is_PDU $true - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/?is_pdu=True' $Result.Headers.Keys.Count | Should -BeExactly 1 } } - + Context -Name "Get-NetboxDCIMDeviceRole" -Fixture { It "Should request the default number of devices types" { $Result = Get-NetboxDCIMDeviceRole - + Assert-VerifiableMock Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 1 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request a device role by Id" { $Result = Get-NetboxDCIMDeviceRole -Id 10 - + Assert-VerifiableMock Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 1 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/10/' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request multiple roles by Id" { $Result = Get-NetboxDCIMDeviceRole -Id 10, 12 - + Assert-VerifiableMock Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 2 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'GET', 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/10/', 'https://netbox.domain.com/api/dcim/device-roles/12/' $Result.Headers.Keys.Count | Should -BeExactly 2 } - + It "Should request single role by Id and color" { $Result = Get-NetboxDCIMDeviceRole -Id 10 -Color '0fab12' - + Assert-VerifiableMock Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 1 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/10/?color=0fab12' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request multiple roles by Id and color" { $Result = Get-NetboxDCIMDeviceRole -Id 10, 12 -Color '0fab12' - + Assert-VerifiableMock Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 2 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'GET', 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/10/?color=0fab12', 'https://netbox.domain.com/api/dcim/device-roles/12/?color=0fab12' $Result.Headers.Keys.Count | Should -BeExactly 2 } - + It "Should request with a limit and offset" { $Result = Get-NetboxDCIMDeviceRole -Limit 10 -Offset 100 - + Assert-VerifiableMock Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 1 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/?offset=100&limit=10' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with a slug" { $Result = Get-NetboxDCIMDeviceRole -Slug 'testdevice' - + Assert-VerifiableMock Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 1 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/?slug=testdevice' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with a name" { $Result = Get-NetboxDCIMDeviceRole -Name 'TestRole' - + Assert-VerifiableMock Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 1 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/?name=TestRole' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request those that are VM role" { $Result = Get-NetboxDCIMDeviceRole -VM_Role $true - + Assert-VerifiableMock Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 1 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/?vm_role=True' $Result.Headers.Keys.Count | Should -BeExactly 1 } } - + Context -Name "New-NetboxDCIMDevice" -Fixture { It "Should create a new device" { $Result = New-NetboxDCIMDevice -Name "newdevice" -Device_Role 4 -Device_Type 10 -Site 1 -Face 0 - + Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'POST' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"site":1,"face":0,"name":"newdevice","status":1,"device_type":10,"device_role":4}' } - + It "Should throw because of an invalid status" { { New-NetboxDCIMDevice -Name "newdevice" -Device_Role 4 -Device_Type 10 -Site 1 -Status 5555 } | Should -Throw } } - - + + Mock -CommandName "Get-NetboxDCIMDevice" -ModuleName NetboxPS -MockWith { return [pscustomobject]@{ 'Id' = $Id 'Name' = $Name } } - + Context -Name "Set-NetboxDCIMDevice" -Fixture { It "Should set a device to a new name" { $Result = Set-NetboxDCIMDevice -Id 1234 -Name 'newtestname' -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Get-NetboxDCIMDevice' -Times 1 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'PATCH' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/devices/1234/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"name":"newtestname"}' } - + It "Should set a device with new properties" { $Result = Set-NetboxDCIMDevice -Id 1234 -Name 'newtestname' -Cluster 10 -Platform 20 -Site 15 -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Get-NetboxDCIMDevice' -Times 1 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'PATCH' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/devices/1234/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"cluster":10,"platform":20,"name":"newtestname","site":15}' } - + It "Should set multiple devices with new properties" { $Result = Set-NetboxDCIMDevice -Id 1234, 3214 -Cluster 10 -Platform 20 -Site 15 -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Get-NetboxDCIMDevice' -Times 2 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'PATCH', 'PATCH' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/devices/1234/', 'https://netbox.domain.com/api/dcim/devices/3214/' $Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Body | Should -Be '{"cluster":10,"platform":20,"site":15}', '{"cluster":10,"platform":20,"site":15}' } - + It "Should set multiple devices with new properties from the pipeline" { $Result = @( [pscustomobject]@{ @@ -414,51 +414,51 @@ Describe -Name "DCIM Devices Tests" -Tag 'DCIM', 'Devices' -Fixture { 'id' = 3241 } ) | Set-NetboxDCIMDevice -Cluster 10 -Platform 20 -Site 15 -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Get-NetboxDCIMDevice' -Times 2 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'PATCH', 'PATCH' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/devices/4432/', 'https://netbox.domain.com/api/dcim/devices/3241/' $Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Body | Should -Be '{"cluster":10,"platform":20,"site":15}', '{"cluster":10,"platform":20,"site":15}' } } - + Context -Name "Remove-NetboxDCIMDevice" -Fixture { It "Should remove a device" { $Result = Remove-NetboxDCIMDevice -Id 10 -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Get-NetboxDCIMDevice' -Times 1 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'DELETE' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/devices/10/' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should remove multiple devices" { $Result = Remove-NetboxDCIMDevice -Id 10, 12 -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Get-NetboxDCIMDevice' -Times 2 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'DELETE', 'DELETE' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/devices/10/', 'https://netbox.domain.com/api/dcim/devices/12/' $Result.Headers.Keys.Count | Should -BeExactly 2 } - + It "Should remove a device from the pipeline" { $Result = Get-NetboxDCIMDevice -Id 20 | Remove-NetboxDCIMDevice -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Get-NetboxDCIMDevice' -Times 2 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'DELETE' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/devices/20/' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should remove mulitple devices from the pipeline" { $Result = @( [pscustomobject]@{ @@ -468,10 +468,10 @@ Describe -Name "DCIM Devices Tests" -Tag 'DCIM', 'Devices' -Fixture { 'Id' = 40 } ) | Remove-NetboxDCIMDevice -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Get-NetboxDCIMDevice' -Times 2 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'DELETE', 'DELETE' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/devices/30/', 'https://netbox.domain.com/api/dcim/devices/40/' $Result.Headers.Keys.Count | Should -BeExactly 2 diff --git a/Tests/DCIM.Interfaces.Tests.ps1 b/Tests/DCIM.Interfaces.Tests.ps1 index b903e08..5499ce7 100644 --- a/Tests/DCIM.Interfaces.Tests.ps1 +++ b/Tests/DCIM.Interfaces.Tests.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.152 @@ -24,7 +24,7 @@ Describe -Name "DCIM Interfaces Tests" -Tag 'DCIM', 'Interfaces' -Fixture { Mock -CommandName 'CheckNetboxIsConnected' -Verifiable -ModuleName 'NetboxPS' -MockWith { return $true } - + Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith { # Return a hashtable of the items we would normally pass to Invoke-RestMethod return [ordered]@{ @@ -36,107 +36,107 @@ Describe -Name "DCIM Interfaces Tests" -Tag 'DCIM', 'Interfaces' -Fixture { 'Body' = $Body } } - + Mock -CommandName 'Get-NetboxCredential' -Verifiable -ModuleName 'NetboxPS' -MockWith { return [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force)) } - + Mock -CommandName 'Get-NetboxHostname' -Verifiable -ModuleName 'NetboxPS' -MockWith { return 'netbox.domain.com' } - + InModuleScope -ModuleName 'NetboxPS' -ScriptBlock { $script:NetboxConfig.Choices.DCIM = (Get-Content "$PSScriptRoot\DCIMChoices.json" -ErrorAction Stop | ConvertFrom-Json) - + Context -Name "Get-NetboxDCIMInterface" -Fixture { It "Should request the default number of interfaces" { $Result = Get-NetboxDCIMInterface - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/interfaces/' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with a limit and offset" { $Result = Get-NetboxDCIMInterface -Limit 10 -Offset 100 - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/interfaces/?offset=100&limit=10' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with enabled" { $Result = Get-NetboxDCIMInterface -Enabled $true - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interfaces/?enabled=True' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with a form factor name" { $Result = Get-NetboxDCIMInterface -Form_Factor '10GBASE-T (10GE)' - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/interfaces/?form_factor=1150' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should throw for an invalid form factor" { { Get-NetboxDCIMInterface -Form_Factor 'Fake' } | Should -Throw } - + It "Should request devices that are mgmt only" { $Result = Get-NetboxDCIMInterface -MGMT_Only $True - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interfaces/?mgmt_only=True' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request an interface from the pipeline" { $Result = [pscustomobject]@{ 'Id' = 1234 } | Get-NetboxDCIMInterface - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/interfaces/1234/' $Result.Headers.Keys.Count | Should -BeExactly 1 } } - + Context -Name "Add-NetboxDCIMInterface" -Fixture { It "Should add a basic interface to a device" { $Result = Add-NetboxDCIMInterface -Device 111 -Name "TestInterface" - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'POST' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interfaces/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"name":"TestInterface","device":111}' } - + It "Should add an interface to a device with lots of properties" { $paramAddNetboxDCIMInterface = @{ Device = 123 @@ -147,77 +147,77 @@ Describe -Name "DCIM Interfaces Tests" -Tag 'DCIM', 'Interfaces' -Fixture { Description = 'Test Description' Mode = 'Access' } - + $Result = Add-NetboxDCIMInterface @paramAddNetboxDCIMInterface - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'POST' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interfaces/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"mtu":9000,"mgmt_only":true,"description":"Test Description","mode":100,"name":"TestInterface","device":123,"form_factor":1150}' } - + It "Should add an interface with multiple tagged VLANs" { $Result = Add-NetboxDCIMInterface -Device 444 -Name "TestInterface" -Mode 'Tagged' -Tagged_VLANs 1, 2, 3, 4 - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'POST' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interfaces/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"mode":200,"name":"TestInterface","device":444,"tagged_vlans":[1,2,3,4]}' } - + It "Should throw for invalid mode" { { Add-NetboxDCIMInterface -Device 321 -Name "Test123" -Mode 'Fake' } | Should -Throw } - + It "Should throw for out of range VLAN" { { Add-NetboxDCIMInterface -Device 321 -Name "Test123" -Untagged_VLAN 4100 } | Should -Throw } } - - + + Mock -CommandName "Get-NetboxDCIMInterface" -ModuleName "NetboxPS" -MockWith { return [pscustomobject]@{ 'Id' = $Id } } - + Context -Name "Set-NetboxDCIMInterface" -Fixture { It "Should set an interface to a new name" { $Result = Set-NetboxDCIMInterface -Id 123 -Name "TestInterface" - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Get-NetboxDCIMInterface' -Times 1 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'PATCH' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interfaces/123/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"name":"TestInterface"}' } - + It "Should set multiple interfaces to a new name" { $Result = Set-NetboxDCIMInterface -Id 456, 789 -Name "TestInterface" - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Get-NetboxDCIMInterface' -Times 2 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 2 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'PATCH', 'PATCH' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interfaces/456/', 'https://netbox.domain.com/api/dcim/interfaces/789/' $Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Body | Should -Be '{"name":"TestInterface"}', '{"name":"TestInterface"}' } - + It "Should set multiple interfaces to a new name from the pipeline" { $Result = @( [pscustomobject]@{ @@ -227,58 +227,58 @@ Describe -Name "DCIM Interfaces Tests" -Tag 'DCIM', 'Interfaces' -Fixture { 'Id' = 4231 } ) | Set-NetboxDCIMInterface -Name "TestInterface" - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Get-NetboxDCIMInterface' -Times 2 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 2 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'PATCH', 'PATCH' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interfaces/1234/', 'https://netbox.domain.com/api/dcim/interfaces/4231/' $Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Body | Should -Be '{"name":"TestInterface"}', '{"name":"TestInterface"}' } - + It "Should throw for invalid form factor" { { Set-NetboxDCIMInterface -Id 1234 -Form_Factor 'fake' } | Should -Throw } } - + Context -Name "Remove-NetboxDCIMInterface" -Fixture { It "Should remove an interface" { $Result = Remove-NetboxDCIMInterface -Id 10 -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Get-NetboxDCIMInterface' -Times 1 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'DELETE' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/interfaces/10/' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should remove multiple interfaces" { $Result = Remove-NetboxDCIMInterface -Id 10, 12 -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Get-NetboxDCIMInterface' -Times 2 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'DELETE', 'DELETE' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/interfaces/10/', 'https://netbox.domain.com/api/dcim/interfaces/12/' $Result.Headers.Keys.Count | Should -BeExactly 2 } - + It "Should remove an interface from the pipeline" { $Result = Get-NetboxDCIMInterface -Id 20 | Remove-NetboxDCIMInterface -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Get-NetboxDCIMInterface' -Times 2 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'DELETE' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/interfaces/20/' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should remove mulitple interfaces from the pipeline" { $Result = @( [pscustomobject]@{ @@ -288,124 +288,124 @@ Describe -Name "DCIM Interfaces Tests" -Tag 'DCIM', 'Interfaces' -Fixture { 'Id' = 40 } ) | Remove-NetboxDCIMInterface -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Get-NetboxDCIMInterface' -Times 2 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'DELETE', 'DELETE' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/interfaces/30/', 'https://netbox.domain.com/api/dcim/interfaces/40/' $Result.Headers.Keys.Count | Should -BeExactly 2 } } - - + + Context -Name "Get-NetboxDCIMInterfaceConnection" -Fixture { It "Should request the default number of interface connections" { $Result = Get-NetboxDCIMInterfaceConnection - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/interface-connections/' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with a limit and offset" { $Result = Get-NetboxDCIMInterfaceConnection -Limit 10 -Offset 100 - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/interface-connections/?offset=100&limit=10' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request connected interfaces" { $Result = Get-NetboxDCIMInterfaceConnection -Connection_Status 'Connected' - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interface-connections/?connection_status=True' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should throw for an invalid connection status" { { Get-NetboxDCIMInterfaceConnection -Connection_Status 'Fake' } | Should -Throw } } - + Context -Name "Add-NetboxDCIMInterfaceConnection" -Fixture { It "Should add a new interface connection" { $Result = Add-NetboxDCIMInterfaceConnection -Interface_A 21 -Interface_B 22 - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'POST' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interface-connections/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"interface_b":22,"interface_a":21}' } - + It "Should throw because of an invalid connection status" { { Add-NetboxDCIMInterfaceConnection -Interface_A 21 -Interface_B 22 -Connection_Status 'fake' } | Should -Throw } } - - + + Mock -CommandName "Get-NetboxDCIMInterfaceConnection" -ModuleName 'NetboxPS' -MockWith { [pscustomobject]@{ 'Id' = $Id } } - + Context -Name "Set-NetboxDCIMInterfaceConnection" -Fixture { It "Should set an interface connection" { $Result = Set-NetboxDCIMInterfaceConnection -Id 123 -Interface_B 2 -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'PATCH' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interface-connections/123/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"interface_b":2}' } - + It "Should set multiple interface connections to a new status" { $Result = Set-NetboxDCIMInterfaceConnection -Id 456, 789 -Connection_Status 'Planned' -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 2 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'PATCH', 'PATCH' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interface-connections/456/', 'https://netbox.domain.com/api/dcim/interface-connections/789/' $Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Body | Should -Be '{"connection_status":false}', '{"connection_status":false}' } - + It "Should set an interface connection from the pipeline" { $Result = [pscustomobject]@{ 'id' = 3 } | Set-NetboxDCIMInterfaceConnection -Connection_Status 'Planned' -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'PATCH' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interface-connections/3/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"connection_status":false}' } - + It "Should set multiple interface connections from the pipeline" { $Result = @( [pscustomobject]@{ @@ -415,57 +415,57 @@ Describe -Name "DCIM Interfaces Tests" -Tag 'DCIM', 'Interfaces' -Fixture { 'id' = 789 } ) | Set-NetboxDCIMInterfaceConnection -Connection_Status 'Planned' -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 2 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'PATCH', 'PATCH' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interface-connections/456/', 'https://netbox.domain.com/api/dcim/interface-connections/789/' $Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Body | Should -Be '{"connection_status":false}', '{"connection_status":false}' } - + It "Should throw trying to set multiple connections to the same interface" { { Set-NetboxDCIMInterfaceConnection -Id 456, 789 -Interface_B 22 -Force } | Should -Throw -ExpectedMessage "Cannot set multiple connections to the same interface" } } - + Context -Name "Remove-NetboxDCIMInterfaceConnection" -Fixture { It "Should remove an interface connection" { $Result = Remove-NetboxDCIMInterfaceConnection -Id 10 -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Get-NetboxDCIMInterfaceConnection' -Times 1 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'DELETE' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/interface-connections/10/' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should remove multiple interface connections" { $Result = Remove-NetboxDCIMInterfaceConnection -Id 10, 12 -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Get-NetboxDCIMInterfaceConnection' -Times 2 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'DELETE', 'DELETE' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/interface-connections/10/', 'https://netbox.domain.com/api/dcim/interface-connections/12/' $Result.Headers.Keys.Count | Should -BeExactly 2 } - + It "Should remove an interface connection from the pipeline" { $Result = Get-NetboxDCIMInterfaceConnection -Id 20 | Remove-NetboxDCIMInterfaceConnection -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Get-NetboxDCIMInterfaceConnection' -Times 2 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'DELETE' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/interface-connections/20/' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should remove mulitple interface connections from the pipeline" { $Result = @( [pscustomobject]@{ @@ -475,10 +475,10 @@ Describe -Name "DCIM Interfaces Tests" -Tag 'DCIM', 'Interfaces' -Fixture { 'Id' = 40 } ) | Remove-NetboxDCIMInterfaceConnection -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Get-NetboxDCIMInterfaceConnection' -Times 2 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'DELETE', 'DELETE' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/interface-connections/30/', 'https://netbox.domain.com/api/dcim/interface-connections/40/' $Result.Headers.Keys.Count | Should -BeExactly 2 diff --git a/Tests/DCIM.Platforms.Tests.ps1 b/Tests/DCIM.Platforms.Tests.ps1 index a909bc6..7d2853a 100644 --- a/Tests/DCIM.Platforms.Tests.ps1 +++ b/Tests/DCIM.Platforms.Tests.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.152 @@ -24,7 +24,7 @@ Describe -Name "DCIM Platforms Tests" -Tag 'DCIM', 'platforms' -Fixture { Mock -CommandName 'CheckNetboxIsConnected' -Verifiable -ModuleName 'NetboxPS' -MockWith { return $true } - + Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith { # Return a hashtable of the items we would normally pass to Invoke-RestMethod return [ordered]@{ @@ -36,78 +36,78 @@ Describe -Name "DCIM Platforms Tests" -Tag 'DCIM', 'platforms' -Fixture { 'Body' = $Body } } - + Mock -CommandName 'Get-NetboxCredential' -Verifiable -ModuleName 'NetboxPS' -MockWith { return [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force)) } - + Mock -CommandName 'Get-NetboxHostname' -Verifiable -ModuleName 'NetboxPS' -MockWith { return 'netbox.domain.com' } - + InModuleScope -ModuleName 'NetboxPS' -ScriptBlock { Context -Name "Get-NetboxDCIMPlatform" -Fixture { It "Should request the default number of platforms" { $Result = Get-NetboxDCIMPlatform - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/platforms/' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with a limit and offset" { $Result = Get-NetboxDCIMPlatform -Limit 10 -Offset 100 - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/platforms/?offset=100&limit=10' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with a platform name" { $Result = Get-NetboxDCIMPlatform -Name "Windows Server 2016" - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/platforms/?name=Windows+Server+2016' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request a platform by manufacturer" { $Result = Get-NetboxDCIMPlatform -Manufacturer 'Cisco' - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/platforms/?manufacturer=Cisco' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request a platform by ID" { $Result = Get-NetboxDCIMPlatform -Id 10 - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/platforms/10/' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request multiple platforms by ID" { $Result = Get-NetboxDCIMPlatform -Id 10, 20 - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 2 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'GET', 'GET' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/platforms/10/', 'https://netbox.domain.com/api/dcim/platforms/20/' $Result.Headers.Keys.Count | Should -BeExactly 2 diff --git a/Tests/Helpers.Tests.ps1 b/Tests/Helpers.Tests.ps1 index 26ea592..594209d 100644 --- a/Tests/Helpers.Tests.ps1 +++ b/Tests/Helpers.Tests.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.150 @@ -26,17 +26,17 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture { Check-NetboxIsConnected } | Should -Throw } - + Mock -CommandName 'CheckNetboxIsConnected' -MockWith { return $true } -ModuleName 'NetboxPS' - + InModuleScope -ModuleName 'NetboxPS' -ScriptBlock { Context -Name "Building URIBuilder" -Fixture { It "Should give a basic URI object" { BuildNewURI -HostName 'netbox.domain.com' | Should -BeOfType [System.UriBuilder] } - + It "Should generate a URI using only a supplied hostname" { $URIBuilder = BuildNewURI -Hostname "netbox.domain.com" $URIBuilder.Host | Should -BeExactly 'netbox.domain.com' @@ -45,51 +45,51 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture { $URIBuilder.Port | Should -Be 443 $URIBuilder.URI.AbsoluteUri | Should -Be 'https://netbox.domain.com/api//' } - + It "Should generate a URI using a hostname and segments" { $URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2' $URIBuilder.Host | Should -BeExactly 'netbox.domain.com' $URIBuilder.Path | Should -BeExactly 'api/seg1/seg2/' $URIBuilder.URI.AbsoluteUri | Should -BeExactly 'https://netbox.domain.com/api/seg1/seg2/' } - + It "Should generate a URI using insecure HTTP and default to port 80" { $URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2' -HTTPS $false -WarningAction 'SilentlyContinue' $URIBuilder.Scheme | Should -Be 'http' $URIBuilder.Port | Should -Be 80 $URIBuilder.URI.AbsoluteURI | Should -Be 'http://netbox.domain.com/api/seg1/seg2/' } - + It "Should generate a URI using HTTPS on port 1234" { $URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2' -Port 1234 $URIBuilder.Scheme | Should -Be 'https' $URIBuilder.Port | Should -Be 1234 $URIBuilder.URI.AbsoluteURI | Should -BeExactly 'https://netbox.domain.com:1234/api/seg1/seg2/' } - + It "Should generate a URI using HTTP on port 4321" { $URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2' -HTTPS $false -Port 4321 -WarningAction 'SilentlyContinue' $URIBuilder.Scheme | Should -Be 'http' $URIBuilder.Port | Should -Be 4321 $URIBuilder.URI.AbsoluteURI | Should -BeExactly 'http://netbox.domain.com:4321/api/seg1/seg2/' } - + It "Should generate a URI with parameters" { $URIParameters = @{ 'param1' = 'paramval1' 'param2' = 'paramval2' } - + $URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2' -Parameters $URIParameters $URIBuilder.Query | Should -BeExactly '?param1=paramval1¶m2=paramval2' $URIBuilder.URI.AbsoluteURI | Should -BeExactly 'https://netbox.domain.com/api/seg1/seg2/?param1=paramval1¶m2=paramval2' } } - + Context -Name "Building URI components" -Fixture { It "Should give a basic hashtable" { $URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'param1' = 1} - + $URIComponents | Should -BeOfType [hashtable] $URIComponents.Keys.Count | Should -BeExactly 2 $URIComponents.Keys | Should -Be @("Segments", "Parameters") @@ -98,10 +98,10 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture { $URIComponents.Parameters | Should -BeOfType [hashtable] $URIComponents.Parameters['param1'] | Should -Be 1 } - + It "Should add a single ID parameter to the segments" { $URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'id' = 123} - + $URIComponents | Should -BeOfType [hashtable] $URIComponents.Keys.Count | Should -BeExactly 2 $URIComponents.Keys | Should -Be @("Segments", "Parameters") @@ -109,10 +109,10 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture { $URIComponents.Parameters.Count | Should -BeExactly 0 $URIComponents.Parameters | Should -BeOfType [hashtable] } - + It "Should add multiple IDs to the parameters id__in" { $URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'id' = "123", "456"} - + $URIComponents | Should -BeOfType [hashtable] $URIComponents.Keys.Count | Should -BeExactly 2 $URIComponents.Keys | Should -Be @("Segments", "Parameters") @@ -121,10 +121,10 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture { $URIComponents.Parameters | Should -BeOfType [hashtable] $URIComponents.Parameters['id__in'] | Should -Be '123,456' } - + It "Should skip a particular parameter name" { $URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'param1' = 1; 'param2' = 2} -SkipParameterByName 'param2' - + $URIComponents | Should -BeOfType [hashtable] $URIComponents.Keys.Count | Should -BeExactly 2 $URIComponents.Keys | Should -Be @("Segments", "Parameters") @@ -134,10 +134,10 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture { $URIComponents.Parameters['param1'] | Should -Be 1 $URIComponents.Parameters['param2'] | Should -BeNullOrEmpty } - + It "Should add a query (q) parameter" { $URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'query' = 'mytestquery'} - + $URIComponents | Should -BeOfType [hashtable] $URIComponents.Keys.Count | Should -BeExactly 2 $URIComponents.Keys | Should -Be @("Segments", "Parameters") @@ -146,7 +146,7 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture { $URIComponents.Parameters | Should -BeOfType [hashtable] $URIComponents.Parameters['q'] | Should -Be 'mytestquery' } - + It "Should generate custom field parameters" { $URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{ 'CustomFields' = @{ @@ -154,7 +154,7 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture { 'Customer_Id' = 'abc' } } - + $URIComponents | Should -BeOfType [hashtable] $URIComponents.Keys.Count | Should -BeExactly 2 $URIComponents.Keys | Should -Be @("Segments", "Parameters") @@ -165,7 +165,7 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture { $URIComponents.Parameters['cf_customer_id'] | Should -Be 'abc' } } - + Context -Name "Invoking request tests" -Fixture { Mock -CommandName 'Invoke-RestMethod' -Verifiable -MockWith { # Return an object of the items we would normally pass to Invoke-RestMethod @@ -179,29 +179,29 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture { 'results' = 'Only results' } } - + Mock -CommandName 'Get-NetboxCredential' -Verifiable -ModuleName 'NetboxPS' -MockWith { return [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force)) } - + It "Should return direct results instead of the raw request" { $URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2' - + $Result = InvokeNetboxRequest -URI $URIBuilder - + Assert-VerifiableMock - + $Result | Should -BeOfType [string] $Result | Should -BeExactly "Only results" } - + It "Should generate a basic request" { $URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2' - + $Result = InvokeNetboxRequest -URI $URIBuilder -Raw - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be $URIBuilder.Uri.AbsoluteUri $Result.Headers | Should -BeOfType [System.Collections.HashTable] @@ -210,49 +210,49 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture { $Result.ContentType | Should -Be 'application/json' $Result.Body | Should -Be $null # We did not supply a body } - + It "Should generate a POST request with body" { $URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2' - + $Result = InvokeNetboxRequest -URI $URIBuilder -Method POST -Body @{ 'bodyparam1' = 'val1' } -Raw - + Assert-VerifiableMock - + $Result.Method | Should -Be 'POST' $Result.Body | Should -Be '{"bodyparam1":"val1"}' } - + It "Should generate a POST request with an extra header" { $Headers = @{ 'Connection' = 'keep-alive' } - + $Body = @{ 'bodyparam1' = 'val1' } - + $URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2' - + $Result = InvokeNetboxRequest -URI $URIBuilder -Method POST -Body $Body -Headers $Headers -Raw - + Assert-VerifiableMock - + $Result.Method | Should -Be 'POST' $Result.Body | Should -Be '{"bodyparam1":"val1"}' $Result.Headers.Count | Should -BeExactly 2 $Result.Headers.Authorization | Should -Be "Token faketoken" $Result.Headers.Connection | Should -Be "keep-alive" } - + It "Should throw because of an invalid method" { { $URI = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2' InvokeNetboxRequest -URI $URI -Method 'Fake' } | Should -Throw } - + It "Should throw because of an out-of-range timeout" { { $URI = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2' @@ -260,222 +260,222 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture { } | Should -Throw } } - + Context -Name "Validating choices" -Fixture { Context -Name "Virtualization choices" -Fixture { $MajorObject = 'Virtualization' $script:NetboxConfig.Choices.Virtualization = (Get-Content "$PSScriptRoot\VirtualizationChoices.json" -ErrorAction Stop | ConvertFrom-Json) - + It "Should return a valid integer for status when provided a name" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName 'virtual-machine:status' -ProvidedValue 'Active' - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 1 } - + It "Should return a valid integer for status when provided an integer" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName 'virtual-machine:status' -ProvidedValue 0 - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 0 } - + It "Should throw because of an invalid choice" { { ValidateChoice -MajorObject $MajorObject -ChoiceName 'virtual-machine:status' -ProvidedValue 'Fake' } | Should -Throw } } - + Context -Name "IPAM choices" -Fixture { $MajorObject = 'IPAM' $script:NetboxConfig.Choices.IPAM = (Get-Content "$PSScriptRoot\IPAMChoices.json" -ErrorAction Stop | ConvertFrom-Json) - + Context -Name "aggregate:family" -Fixture { $ChoiceName = 'aggregate:family' - + It "Should return a valid integer when provided a name" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'IPv4' - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 4 } - + It "Should return a valid integer when provided an integer" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 4 - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 4 } - + It "Should throw because of an invalid choice" { { ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 0 } | Should -Throw } } - + Context -Name "prefix:family" { $ChoiceName = 'prefix:family' - + It "Should return a valid integer when provided a name" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'IPv4' - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 4 } - + It "Should return a valid integer when provided an integer" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 4 - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 4 } - + It "Should throw because of an invalid choice" { { ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 0 } | Should -Throw } } - + Context -Name "prefix:status" { $ChoiceName = 'prefix:status' - + It "Should return a valid integer when provided a name" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Active' - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 1 } - + It "Should return a valid integer when provided an integer" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 1 - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 1 } - + It "Should throw because of an invalid choice" { { ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 10 } | Should -Throw } } - + Context -Name "ip-address:family" { $ChoiceName = 'ip-address:family' - + It "Should return a valid integer when provided a name" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'IPv4' - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 4 } - + It "Should return a valid integer when provided an integer" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 4 - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 4 } - + It "Should throw because of an invalid choice" { { ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 10 } | Should -Throw } } - + Context -Name "ip-address:status" { $ChoiceName = 'ip-address:status' - + It "Should return a valid integer when provided a name" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Active' - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 1 } - + It "Should return a valid integer when provided an integer" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 1 - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 1 } - + It "Should throw because of an invalid choice" { { ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 10 } | Should -Throw } } - + Context -Name "ip-address:role" { $ChoiceName = 'ip-address:role' - + It "Should return a valid integer when provided a name" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Anycast' - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 30 } - + It "Should return a valid integer when provided an integer" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 30 - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 30 } - + It "Should throw because of an invalid choice" { { ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 1 } | Should -Throw } } - + Context -Name "vlan:status" { $ChoiceName = 'vlan:status' - + It "Should return a valid integer when provided a name" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Active' - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 1 } - + It "Should return a valid integer when provided an integer" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 1 - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 1 } - + It "Should throw because of an invalid choice" { { ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 0 } | Should -Throw } } - + Context -Name "service:protocol" { $ChoiceName = 'service:protocol' - + It "Should return a valid integer when provided a name" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'TCP' - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 6 } - + It "Should return a valid integer when provided an integer" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 6 - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 6 } - + It "Should throw because of an invalid choice" { { ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 0 @@ -483,241 +483,241 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture { } } } - + Context -Name "DCIM choices" -Fixture { $MajorObject = 'DCIM' $script:NetboxConfig.Choices.DCIM = (Get-Content "$PSScriptRoot\DCIMChoices.json" -ErrorAction Stop | ConvertFrom-Json) - + Context -Name "device:face" -Fixture { $ChoiceName = 'device:face' - + It "Should return a valid integer when provided a name" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Front' - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 0 } - + It "Should return a valid integer when provided an integer" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 1 - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 1 } - + It "Should throw because of an invalid choice" { { ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake' } | Should -Throw } } - + Context -Name "device:status" -Fixture { $ChoiceName = 'device:status' - + It "Should return a valid integer when provided a name" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Active' - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 1 } - + It "Should return a valid integer when provided an integer" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 0 - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 0 } - + It "Should throw because of an invalid choice" { { ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake' } | Should -Throw } } - + Context -Name "console-port:connection_status" -Fixture { $ChoiceName = 'console-port:connection_status' - + It "Should return a valid string when provided a name" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Planned' - + $Result | Should -BeOfType [bool] $Result | Should -Be $false } - + It "Should return a valid string when provided a string" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'false' - + $Result | Should -BeOfType [bool] $Result | Should -Be $false } - + It "Should return a valid string when provided a boolean" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue $true - + $Result | Should -BeOfType [bool] $Result | Should -Be $true } - + It "Should throw because of an invalid choice" { { ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake' } | Should -Throw } } - + Context -Name "interface:form_factor" -Fixture { $ChoiceName = 'interface:form_factor' - + It "Should return a valid integer when provided a name" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue '10GBASE-CX4 (10GE)' - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 1170 } - + It "Should return a valid integer when provided an integer" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 1500 - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 1500 } - + It "Should throw because of an invalid choice" { { ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake' } | Should -Throw } } - + Context -Name "interface-connection:connection_status" -Fixture { $ChoiceName = 'interface-connection:connection_status' - + It "Should return a valid string when provided a name" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Planned' - + $Result | Should -BeOfType [bool] $Result | Should -Be $false } - + It "Should return a valid string when provided a string" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'false' - + $Result | Should -BeOfType [bool] $Result | Should -Be $false } - + It "Should return a valid string when provided a boolean" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue $true - + $Result | Should -BeOfType [bool] $Result | Should -Be $true } - + It "Should throw because of an invalid choice" { { ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake' } | Should -Throw } } - + Context -Name "interface-template:form_factor" -Fixture { $ChoiceName = 'interface-template:form_factor' - + It "Should return a valid integer when provided a name" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue '10GBASE-CX4 (10GE)' - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 1170 } - + It "Should return a valid integer when provided an integer" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 1500 - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 1500 } - + It "Should throw because of an invalid choice" { { ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake' } | Should -Throw } } - + Context -Name "power-port:connection_status" -Fixture { $ChoiceName = 'power-port:connection_status' - + It "Should return a valid string when provided a name" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Planned' - + $Result | Should -BeOfType [bool] $Result | Should -Be $false } - + It "Should return a valid string when provided a string" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'false' - + $Result | Should -BeOfType [bool] $Result | Should -Be $false } - + It "Should return a valid string when provided a boolean" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue $true - + $Result | Should -BeOfType [bool] $Result | Should -Be $true } - + It "Should throw because of an invalid choice" { { ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake' } | Should -Throw } } - + Context -Name "rack:type" -Fixture { $ChoiceName = 'rack:type' - + It "Should return a valid integer when provided a name" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue '2-post frame' - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 100 } - + It "Should return a valid integer when provided an integer" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 300 - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 300 } - + It "Should throw because of an invalid choice" { { ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake' } | Should -Throw } } - + Context -Name "rack:width" -Fixture { $ChoiceName = 'rack:width' - + It "Should return a valid integer when provided a name" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue '19 inches' - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 19 } - + It "Should return a valid integer when provided an integer" { $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 23 - + $Result | Should -BeOfType [uint16] $Result | Should -BeExactly 23 } - + It "Should throw because of an invalid choice" { { ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake' diff --git a/Tests/IPAM.Tests.ps1 b/Tests/IPAM.Tests.ps1 index 73fa4f4..6b214e9 100644 --- a/Tests/IPAM.Tests.ps1 +++ b/Tests/IPAM.Tests.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.150 @@ -25,7 +25,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture { Mock -CommandName 'CheckNetboxIsConnected' -Verifiable -ModuleName 'NetboxPS' -MockWith { return $true } - + Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith { # Return a hashtable of the items we would normally pass to Invoke-RestMethod return [ordered]@{ @@ -37,387 +37,387 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture { 'Body' = $Body } } - + Mock -CommandName 'Get-NetboxCredential' -Verifiable -ModuleName 'NetboxPS' -MockWith { return [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force)) } - + Mock -CommandName 'Get-NetboxHostname' -Verifiable -ModuleName 'NetboxPS' -MockWith { return 'netbox.domain.com' } - + InModuleScope -ModuleName 'NetboxPS' -ScriptBlock { $script:NetboxConfig.Choices.IPAM = (Get-Content "$PSScriptRoot\IPAMChoices.json" -ErrorAction Stop | ConvertFrom-Json) Context -Name "Get-NetboxIPAMAggregate" -Fixture { It "Should request the default number of aggregates" { $Result = Get-NetboxIPAMAggregate - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Authorization | Should -Be "Token faketoken" } - + It "Should request with limit and offset" { $Result = Get-NetboxIPAMAggregate -Limit 10 -Offset 12 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?offset=12&limit=10' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Authorization | Should -Be "Token faketoken" } - + It "Should request with a query" { $Result = Get-NetboxIPAMAggregate -Query '10.10.0.0' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?q=10.10.0.0' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Authorization | Should -Be "Token faketoken" } - + It "Should request with an escaped query" { $Result = Get-NetboxIPAMAggregate -Query 'my aggregate' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?q=my+aggregate' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Authorization | Should -Be "Token faketoken" } - + It "Should request with a single ID" { $Result = Get-NetboxIPAMAggregate -Id 10 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/10/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Authorization | Should -Be "Token faketoken" } - + It "Should request with multiple IDs" { $Result = Get-NetboxIPAMAggregate -Id 10, 12, 15 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?id__in=10,12,15' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Authorization | Should -Be "Token faketoken" } } - + Context -Name "Get-NetboxIPAMAddress" -Fixture { It "Should request the default number of addresses" { $Result = Get-NetboxIPAMAddress - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Authorization | Should -Be "Token faketoken" } - + It "Should request with limit and offset" { $Result = Get-NetboxIPAMAddress -Limit 10 -Offset 12 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?offset=12&limit=10' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Authorization | Should -Be "Token faketoken" } - + It "Should request with a query" { $Result = Get-NetboxIPAMAddress -Query '10.10.10.10' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?q=10.10.10.10' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Authorization | Should -Be "Token faketoken" } - + It "Should request with an escaped query" { $Result = Get-NetboxIPAMAddress -Query 'my ip address' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?q=my+ip+address' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Authorization | Should -Be "Token faketoken" } - + It "Should request with a single ID" { $Result = Get-NetboxIPAMAddress -Id 10 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/10/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Authorization | Should -Be "Token faketoken" } - + It "Should request with multiple IDs" { $Result = Get-NetboxIPAMAddress -Id 10, 12, 15 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?id__in=10,12,15' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Authorization | Should -Be "Token faketoken" } - + It "Should request with a family number" { $Result = Get-NetboxIPAMAddress -Family 4 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?family=4' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with a family name" { $Result = Get-NetboxIPAMAddress -Family 'IPv4' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?family=4' $Result.Headers.Keys.Count | Should -BeExactly 1 } } - + Context -Name "Get-NetboxIPAMAvailableIP" -Fixture { It "Should request the default number of available IPs" { $Result = Get-NetboxIPAMAvailableIP -Prefix_Id 10 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/10/available-ips/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Authorization | Should -Be "Token faketoken" } - + It "Should request 10 available IPs" { $Result = Get-NetboxIPAMAvailableIP -Prefix_Id 1504 -NumberOfIPs 10 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/1504/available-ips/?limit=10' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Authorization | Should -Be "Token faketoken" } } - + Context -Name "Get-NetboxIPAMPrefix" -Fixture { It "Should request the default number of prefixes" { $Result = Get-NetboxIPAMPrefix - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Authorization | Should -Be "Token faketoken" } - + It "Should request with limit and offset" { $Result = Get-NetboxIPAMPrefix -Limit 10 -Offset 12 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?offset=12&limit=10' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Authorization | Should -Be "Token faketoken" } - + It "Should request with a query" { $Result = Get-NetboxIPAMPrefix -Query '10.10.10.10' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?q=10.10.10.10' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Authorization | Should -Be "Token faketoken" } - + It "Should request with an escaped query" { $Result = Get-NetboxIPAMPrefix -Query 'my ip address' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?q=my+ip+address' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Authorization | Should -Be "Token faketoken" } - + It "Should request with a single ID" { $Result = Get-NetboxIPAMPrefix -Id 10 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/10/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Authorization | Should -Be "Token faketoken" } - + It "Should request with multiple IDs" { $Result = Get-NetboxIPAMPrefix -Id 10, 12, 15 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?id__in=10,12,15' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Authorization | Should -Be "Token faketoken" } - + It "Should request with VLAN vID" { $Result = Get-NetboxIPAMPrefix -VLAN_VID 10 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?vlan_vid=10' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Authorization | Should -Be "Token faketoken" } - + It "Should request with family of 4" { $Result = Get-NetboxIPAMPrefix -Family 4 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?family=4' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Authorization | Should -Be "Token faketoken" } - + It "Should throw because the mask length is too large" { { Get-NetboxIPAMPrefix -Mask_length 128 } | Should -Throw } - + It "Should throw because the mask length is too small" { { Get-NetboxIPAMPrefix -Mask_length -1 } | Should -Throw } - + It "Should not throw because the mask length is just right" { { Get-NetboxIPAMPrefix -Mask_length 24 } | Should -Not -Throw } - + It "Should request with mask length 24" { $Result = Get-NetboxIPAMPrefix -Mask_length 24 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?mask_length=24' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Authorization | Should -Be "Token faketoken" } } - + Context -Name "New-NetboxIPAMPrefix" -Fixture { It "Should create a basic prefix" { $Result = New-NetboxIPAMPrefix -Prefix "10.0.0.0/24" - + Assert-VerifiableMock - + $Result.Method | Should -Be 'POST' $Result.URI | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"prefix":"10.0.0.0/24","status":1}' } - + It "Should create a prefix with a status and role names" { $Result = New-NetboxIPAMPrefix -Prefix "10.0.0.0/24" -Status 'Active' -Role 'Active' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'POST' $Result.URI | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"prefix":"10.0.0.0/24","status":1,"role":"Active"}' } - + It "Should create a prefix with a status, role name, and tenant ID" { $Result = New-NetboxIPAMPrefix -Prefix "10.0.0.0/24" -Status 'Active' -Role 'Active' -Tenant 15 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'POST' $Result.URI | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"prefix":"10.0.0.0/24","status":1,"tenant":15,"role":"Active"}' } } - + Context -Name "New-NetboxIPAMAddress" -Fixture { It "Should create a basic IP address" { $Result = New-NetboxIPAMAddress -Address '10.0.0.1/24' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'POST' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"status":1,"address":"10.0.0.1/24"}' } - + It "Should create an IP with a status and role names" { $Result = New-NetboxIPAMAddress -Address '10.0.0.1/24' -Status 'Reserved' -Role 'Anycast' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'POST' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"status":2,"address":"10.0.0.1/24","role":30}' } - + It "Should create an IP with a status and role values" { $Result = New-NetboxIPAMAddress -Address '10.0.1.1/24' -Status '1' -Role '10' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'POST' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"status":1,"address":"10.0.1.1/24","role":10}' } } - + Context -Name "Remove-NetboxIPAMAddress" -Fixture { Mock -CommandName "Get-NetboxIPAMAddress" -ModuleName NetboxPS -MockWith { return @{ @@ -425,44 +425,44 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture { 'id' = $id } } - + It "Should remove a single IP" { $Result = Remove-NetboxIPAMAddress -Id 4109 -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 1 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'DELETE' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4109/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be $null } - + It "Should remove a single IP from the pipeline" { $Result = [pscustomobject]@{ 'id' = 4110 } | Remove-NetboxIPAMAddress -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 1 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'DELETE' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4110/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be $null } - - It "Should remove multiple IPs" { + + It "Should remove multiple IPs" { $Result = Remove-NetboxIPAMAddress -Id 4109, 4110 -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 2 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'DELETE', 'DELETE' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4109/', 'https://netbox.domain.com/api/ipam/ip-addresses/4110/' $Result.Headers.Keys.Count | Should -BeExactly 2 } - + It "Should remove multiple IPs from the pipeline" { $Result = @( [pscustomobject]@{ @@ -472,16 +472,16 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture { 'id' = 4110 } ) | Remove-NetboxIPAMAddress -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 2 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'DELETE', 'DELETE' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4109/', 'https://netbox.domain.com/api/ipam/ip-addresses/4110/' $Result.Headers.Keys.Count | Should -BeExactly 2 } } - + Context -Name "Set-NetboxIPAMAddress" -Fixture { Mock -CommandName "Get-NetboxIPAMAddress" -ModuleName NetboxPS -MockWith { return @{ @@ -489,57 +489,57 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture { 'id' = $id } } - + It "Should set an IP with a new status" { $Result = Set-NetboxIPAMAddress -Id 4109 -Status 2 -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 1 -Scope "It" -Exactly - + $Result.Method | Should -Be 'PATCH' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4109/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"status":2}' } - + It "Should set an IP from the pipeline" { $Result = [pscustomobject]@{ 'Id' = 4501 } | Set-NetboxIPAMAddress -VRF 10 -Tenant 14 -Description 'Test description' -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 1 -Scope "It" -Exactly - + $Result.Method | Should -Be 'PATCH' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4501/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"vrf":10,"description":"Test description","tenant":14}' } - + It "Should set mulitple IPs to a new status" { $Result = Set-NetboxIPAMAddress -Id 4109, 4555 -Status 2 -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 2 -Scope "It" -Exactly - + $Result.Method | Should -Be 'PATCH', 'PATCH' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4109/', 'https://netbox.domain.com/api/ipam/ip-addresses/4555/' $Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Body | Should -Be '{"status":2}', '{"status":2}' } - + It "Should set an IP with VRF, Tenant, and Description" { $Result = Set-NetboxIPAMAddress -Id 4110 -VRF 10 -Tenant 14 -Description 'Test description' -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 1 -Scope "It" -Exactly - + $Result.Method | Should -Be 'PATCH' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4110/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"vrf":10,"description":"Test description","tenant":14}' } - + It "Should set multiple IPs from the pipeline" { $Result = @( [pscustomobject]@{ @@ -549,10 +549,10 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture { 'Id' = 4611 } ) | Set-NetboxIPAMAddress -Status 2 -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 2 -Scope "It" -Exactly - + $Result.Method | Should -Be 'PATCH', 'PATCH' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4501/', 'https://netbox.domain.com/api/ipam/ip-addresses/4611/' $Result.Headers.Keys.Count | Should -BeExactly 2 diff --git a/Tests/Setup.Tests.ps1 b/Tests/Setup.Tests.ps1 index 664f3aa..dda6465 100644 --- a/Tests/Setup.Tests.ps1 +++ b/Tests/Setup.Tests.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.150 @@ -24,61 +24,61 @@ Describe "Setup tests" -Tag 'Core', 'Setup' -Fixture { It "Throws an error for an empty hostname" { { Get-NetboxHostname } | Should -Throw } - + It "Sets the hostname" { Set-NetboxHostName -HostName 'netbox.domain.com' | Should -Be 'netbox.domain.com' } - + It "Gets the hostname from the variable" { Get-NetboxHostName | Should -Be 'netbox.domain.com' } - + It "Throws an error for empty credentials" { { Get-NetboxCredential } | Should -Throw } - + Context "Plain text credentials" { It "Sets the credentials using plain text" { Set-NetboxCredential -Token (ConvertTo-SecureString -String "faketoken" -Force -AsPlainText) | Should -BeOfType [pscredential] } - + It "Checks the set credentials" { $Creds = Set-NetboxCredential -Token (ConvertTo-SecureString -String "faketoken" -Force -AsPlainText) (Get-NetboxCredential).GetNetworkCredential().Password | Should -BeExactly "faketoken" } } - + Context "Credentials object" { $Creds = [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force)) - + It "Sets the credentials using [pscredential]" { Set-NetboxCredential -Credential $Creds | Should -BeOfType [pscredential] } - + It "Checks the set credentials" { (Get-NetboxCredential).GetNetworkCredential().Password | Should -BeExactly 'faketoken' } } - + <# Context "Connecting to the API" { Mock Get-NetboxCircuitsChoices { return $true } -ModuleName NetboxPS -Verifiable - + $Creds = [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force)) - + It "Connects using supplied hostname and obtained credentials" { #$null = Set-NetboxCredentials -Credentials $Creds Connect-NetboxAPI -Hostname "fake.org" | Should -Be $true } - + It "Connects using supplied hostname and credentials" { Connect-NetboxAPI -Hostname 'fake.org' -Credentials $Creds | Should -Be $true } - - - + + + Assert-MockCalled -CommandName Get-NetboxCircuitsChoices -ModuleName NetboxPS } #> diff --git a/Tests/Virtualization.Tests.ps1 b/Tests/Virtualization.Tests.ps1 index 327060a..0eb2682 100644 --- a/Tests/Virtualization.Tests.ps1 +++ b/Tests/Virtualization.Tests.ps1 @@ -1,4 +1,4 @@ -<# +<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.150 @@ -24,7 +24,7 @@ Describe -Name "Virtualization tests" -Tag 'Virtualization' -Fixture { Mock -CommandName 'CheckNetboxIsConnected' -Verifiable -ModuleName 'NetboxPS' -MockWith { return $true } - + Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith { # Return a hashtable of the items we would normally pass to Invoke-RestMethod return [ordered]@{ @@ -35,285 +35,285 @@ Describe -Name "Virtualization tests" -Tag 'Virtualization' -Fixture { 'ContentType' = $ContentType 'Body' = $Body } - } - + } + Mock -CommandName 'Get-NetboxCredential' -Verifiable -ModuleName 'NetboxPS' -MockWith { return [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force)) } - + Mock -CommandName 'Get-NetboxHostname' -Verifiable -ModuleName 'NetboxPS' -MockWith { return 'netbox.domain.com' } - + InModuleScope -ModuleName 'NetboxPS' -ScriptBlock { $script:NetboxConfig.Choices.Virtualization = (Get-Content "$PSScriptRoot\VirtualizationChoices.json" -ErrorAction Stop | ConvertFrom-Json) - + Context -Name "Get-NetboxVirtualMachine" -Fixture { It "Should request the default number of VMs" { $Result = Get-NetboxVirtualMachine - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with limit and offset" { $Result = Get-NetboxVirtualMachine -Limit 10 -Offset 12 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/?offset=12&limit=10' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with a query" { $Result = Get-NetboxVirtualMachine -Query 'testvm' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/?q=testvm' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with an escaped query" { $Result = Get-NetboxVirtualMachine -Query 'test vm' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/?q=test+vm' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with a name" { $Result = Get-NetboxVirtualMachine -Name 'testvm' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/?name=testvm' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with a single ID" { $Result = Get-NetboxVirtualMachine -Id 10 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/10/' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with multiple IDs" { $Result = Get-NetboxVirtualMachine -Id 10, 12, 15 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/?id__in=10,12,15' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request a status" { $Result = Get-NetboxVirtualMachine -Status 'Active' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/?status=1' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should throw for an invalid status" { { Get-NetboxVirtualMachine -Status 'Fake' } | Should -Throw } } - + Context -Name "Get-NetboxVirtualMachineInterface" -Fixture { It "Should request the default number of interfaces" { $Result = Get-NetboxVirtualMachineInterface - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with a limit and offset" { $Result = Get-NetboxVirtualMachineInterface -Limit 10 -Offset 12 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/?offset=12&limit=10' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request a interface with a specific ID" { $Result = Get-NetboxVirtualMachineInterface -Id 10 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/10/' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request a name" { $Result = Get-NetboxVirtualMachineInterface -Name 'Ethernet0' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/?name=Ethernet0' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with a VM ID" { $Result = Get-NetboxVirtualMachineInterface -Virtual_Machine_Id 10 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/?virtual_machine_id=10' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with Enabled" { $Result = Get-NetboxVirtualMachineInterface -Enabled $true - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/?enabled=true' $Result.Headers.Keys.Count | Should -BeExactly 1 } } - + Context -Name "Get-NetboxVirtualMachineCluster" -Fixture { It "Should request the default number of clusters" { $Result = Get-NetboxVirtualizationCluster - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with limit and offset" { $Result = Get-NetboxVirtualizationCluster -Limit 10 -Offset 12 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/?offset=12&limit=10' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with a query" { $Result = Get-NetboxVirtualizationCluster -Query 'testcluster' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/?q=testcluster' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with an escaped query" { $Result = Get-NetboxVirtualizationCluster -Query 'test cluster' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/?q=test+cluster' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with a name" { $Result = Get-NetboxVirtualizationCluster -Name 'testcluster' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/?name=testcluster' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with a single ID" { $Result = Get-NetboxVirtualizationCluster -Id 10 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/10/' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with multiple IDs" { $Result = Get-NetboxVirtualizationCluster -Id 10, 12, 15 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/?id__in=10,12,15' $Result.Headers.Keys.Count | Should -BeExactly 1 } } - + Context -Name "Get-NetboxVirtualMachineClusterGroup" -Fixture { It "Should request the default number of cluster groups" { $Result = Get-NetboxVirtualizationClusterGroup - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/cluster-groups/' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with limit and offset" { $Result = Get-NetboxVirtualizationClusterGroup -Limit 10 -Offset 12 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/cluster-groups/?offset=12&limit=10' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with a name" { $Result = Get-NetboxVirtualizationClusterGroup -Name 'testclustergroup' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/cluster-groups/?name=testclustergroup' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should request with a slug" { $Result = Get-NetboxVirtualizationClusterGroup -Slug 'test-cluster-group' - + Assert-VerifiableMock - + $Result.Method | Should -Be 'GET' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/cluster-groups/?slug=test-cluster-group' $Result.Headers.Keys.Count | Should -BeExactly 1 } } - + Context -Name "New-NetboxVirtualMachine" -Fixture { It "Should create a basic VM" { $Result = New-NetboxVirtualMachine -Name 'testvm' -Cluster 1 - + Assert-VerifiableMock $Result.Method | Should -Be 'POST' @@ -321,109 +321,109 @@ Describe -Name "Virtualization tests" -Tag 'Virtualization' -Fixture { $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"cluster":1,"name":"testvm","status":1}' } - + It "Should create a VM with CPUs, Memory, Disk, tenancy, and comments" { $Result = New-NetboxVirtualMachine -Name 'testvm' -Cluster 1 -Status Active -vCPUs 4 -Memory 4096 -Tenant 11 -Disk 50 -Comments "these are comments" - + Assert-VerifiableMock - + $Result.Method | Should -Be 'POST' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"tenant":11,"comments":"these are comments","disk":50,"memory":4096,"name":"testvm","cluster":1,"status":1,"vcpus":4}' } - + It "Should throw because of an invalid status" { { New-NetboxVirtualMachine -Name 'testvm' -Status 1123 -Cluster 1 } | Should -Throw } } - + Context -Name "Add-NetboxVirtualMachineInterface" -Fixture { It "Should add a basic interface" { $Result = Add-NetboxVirtualMachineInterface -Name 'Ethernet0' -Virtual_Machine 10 - + Assert-VerifiableMock - + $Result.Method | Should -Be 'POST' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"virtual_machine":10,"name":"Ethernet0","enabled":true}' } - + It "Should add an interface with a MAC, MTU, and Description" { $Result = Add-NetboxVirtualMachineInterface -Name 'Ethernet0' -Virtual_Machine 10 -Mac_Address '11:22:33:44:55:66' -MTU 1500 -Description "Test description" - + Assert-VerifiableMock - + $Result.Method | Should -Be 'POST' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"mtu":1500,"description":"Test description","enabled":true,"virtual_machine":10,"name":"Ethernet0","mac_address":"11:22:33:44:55:66"}' } } - - + + Mock -CommandName "Get-NetboxVirtualMachine" -ModuleName NetboxPS -MockWith { return [pscustomobject]@{ 'Id' = $Id 'Name' = $Name } } - + Context -Name "Set-NetboxVirtualMachine" -Fixture { It "Should set a VM to a new name" { $Result = Set-NetboxVirtualMachine -Id 1234 -Name 'newtestname' -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 1 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'PATCH' $Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/1234/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"name":"newtestname"}' } - + It "Should set a VM with a new name, cluster, platform, and status" { $Result = Set-NetboxVirtualMachine -Id 1234 -Name 'newtestname' -Cluster 10 -Platform 15 -Status 'Offline' -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 1 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'PATCH' $Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/1234/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"cluster":10,"platform":15,"name":"newtestname","status":0}' } - + It "Should throw because of an invalid status" { { Set-NetboxVirtualMachine -Id 1234 -Status 'Fake' -Force } | Should -Throw - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 0 -Exactly -Scope 'It' } } - - + + Mock -CommandName "Get-NetboxVirtualMachineInterface" -ModuleName NetboxPS -MockWith { return [pscustomobject]@{ 'Id' = $Id 'Name' = $Name } } - + Context -Name "Set-NetboxVirtualMachineInterface" -Fixture { It "Should set an interface to a new name" { $Result = Set-NetboxVirtualMachineInterface -Id 1234 -Name 'newtestname' -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName Get-NetboxVirtualMachineInterface -Times 1 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'PATCH' $Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/1234/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"name":"newtestname"}' } - + It "Should set an interface to a new name, MTU, MAC address and description" { $paramSetNetboxVirtualMachineInterface = @{ Id = 1234 @@ -433,30 +433,30 @@ Describe -Name "Virtualization tests" -Tag 'Virtualization' -Fixture { Description = "Test description" Force = $true } - + $Result = Set-NetboxVirtualMachineInterface @paramSetNetboxVirtualMachineInterface - + Assert-VerifiableMock Assert-MockCalled -CommandName Get-NetboxVirtualMachineInterface -Times 1 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'PATCH' $Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/1234/' $Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Body | Should -Be '{"mac_address":"11:22:33:44:55:66","mtu":9000,"description":"Test description","name":"newtestname"}' } - + It "Should set multiple interfaces to a new name" { $Result = Set-NetboxVirtualMachineInterface -Id 1234, 4321 -Name 'newtestname' -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName Get-NetboxVirtualMachineInterface -Times 2 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'PATCH', 'PATCH' $Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/1234/', 'https://netbox.domain.com/api/virtualization/interfaces/4321/' $Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Body | Should -Be '{"name":"newtestname"}', '{"name":"newtestname"}' } - + It "Should set multiple interfaces to a new name from the pipeline" { $Result = @( [pscustomobject]@{ @@ -466,51 +466,51 @@ Describe -Name "Virtualization tests" -Tag 'Virtualization' -Fixture { 'Id' = 4321 } ) | Set-NetboxVirtualMachineInterface -Name 'newtestname' -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName Get-NetboxVirtualMachineInterface -Times 2 -Scope 'It' -Exactly - + $Result.Method | Should -Be 'PATCH', 'PATCH' $Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/4123/', 'https://netbox.domain.com/api/virtualization/interfaces/4321/' $Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Body | Should -Be '{"name":"newtestname"}', '{"name":"newtestname"}' } } - + Context -Name "Remove-NetboxVirtualMachine" -Fixture { It "Should remove a single VM" { $Result = Remove-NetboxVirtualMachine -Id 4125 -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 1 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'DELETE' $Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/4125/' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should remove mulitple VMs" { $Result = Remove-NetboxVirtualMachine -Id 4125, 4132 -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 2 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'DELETE', 'DELETE' $Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/4125/', 'https://netbox.domain.com/api/virtualization/virtual-machines/4132/' $Result.Headers.Keys.Count | Should -BeExactly 2 } - + It "Should remove a VM from the pipeline" { $Result = Get-NetboxVirtualMachine -Id 4125 | Remove-NetboxVirtualMachine -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 2 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'DELETE' $Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/4125/' $Result.Headers.Keys.Count | Should -BeExactly 1 } - + It "Should remove multiple VMs from the pipeline" { $Result = @( [pscustomobject]@{ @@ -520,10 +520,10 @@ Describe -Name "Virtualization tests" -Tag 'Virtualization' -Fixture { 'Id' = 4132 } ) | Remove-NetboxVirtualMachine -Force - + Assert-VerifiableMock Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 2 -Exactly -Scope 'It' - + $Result.Method | Should -Be 'DELETE', 'DELETE' $Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/4125/', 'https://netbox.domain.com/api/virtualization/virtual-machines/4132/' $Result.Headers.Keys.Count | Should -BeExactly 2 diff --git a/deploy.ps1 b/deploy.ps1 index 644d0f7..1f090a9 100644 --- a/deploy.ps1 +++ b/deploy.ps1 @@ -1,19 +1,19 @@ <# .SYNOPSIS A brief description of the Invoke-deploy_ps1 file. - + .DESCRIPTION A description of the file. - + .PARAMETER SkipVersion A description of the SkipVersion parameter. - + .PARAMETER VersionIncrease A description of the VersionIncrease parameter. - + .PARAMETER NewVersion A description of the NewVersion parameter. - + .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.174 @@ -28,10 +28,10 @@ param ( [Parameter(ParameterSetName = 'SkipVersion')] [switch]$SkipVersion, - + [Parameter(ParameterSetName = 'IncreaseVersion')] [version]$VersionIncrease = "0.0.1", - + [Parameter(ParameterSetName = 'SetVersion')] [version]$NewVersion ) @@ -55,14 +55,14 @@ $Counter = 0 Write-Host "Concatenating [$($PS1Files.Count)] PS1 files from $FunctionPath" foreach ($File in $PS1Files) { $Counter++ - + try { Write-Host (" Adding file {0:D2}/{1:D2}: $($File.Name)" -f $Counter, $PS1Files.Count) - + "`r`n#region File $($File.Name)`r`n" | Out-File -FilePath $ConcatenatedFilePath -Encoding utf8 -Append -ErrorAction Stop - + Get-Content $File.FullName -Encoding UTF8 -ErrorAction Stop | Out-File -FilePath $ConcatenatedFilePath -Encoding utf8 -Append -ErrorAction Stop - + "`r`n#endregion" | Out-File -FilePath $ConcatenatedFilePath -Encoding utf8 -Append -ErrorAction Stop } catch { Write-Host "FAILED TO WRITE CONCATENATED FILE: $($_.Exception.Message): $($_.TargetObject)" -ForegroundColor Red @@ -85,30 +85,30 @@ switch ($PSCmdlet.ParameterSetName) { "SkipVersion" { # Dont do anything with the PSD Write-Host " Skipping version update, maintaining version [$CurrentVersion]" - + break } - + "IncreaseVersion" { # Calculate the new version [version]$NewVersion = "{0}.{1}.{2}" -f ($CurrentVersion.Major + $VersionIncrease.Major), ($CurrentVersion.Minor + $VersionIncrease.Minor), ($CurrentVersion.Build + $VersionIncrease.Build) - + Write-Host " Updating version in PSD1 from [$CurrentVersion] to [$NewVersion]" - + # Replace the version number in the content #$PSDContent -replace $CurrentVersion, $NewVersion | Out-File $PSScriptRoot\$ModuleName.psd1 -Encoding UTF8 Update-ModuleManifest -Path "$PSScriptRoot\$ModuleName.psd1" -ModuleVersion $NewVersion - + break } - + "SetVersion" { Write-Host " Updating version in PSD1 from [$CurrentVersion] to [$NewVersion]" - + # Replace the version number in the content #$PSDContent -replace $CurrentVersion, $NewVersion | Out-File $PSScriptRoot\$ModuleName.psd1 -Encoding UTF8 Update-ModuleManifest -Path "$PSScriptRoot\$ModuleName.psd1" -ModuleVersion $NewVersion - + break } } From 42b00279cb73ba0be99e9a62892f3540f561a243 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Fri, 23 Jul 2021 22:12:46 +0200 Subject: [PATCH 25/68] Add release.(yml) Github Actions (#21) It will push on PSGallery module when release a new version ! --- .github/workflows/release.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..7269292 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,16 @@ +name: Release + +on: + release: + types: [published] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + - name: Publish + run: | + pwsh -Command "Publish-Module -Path ./NetboxPS -NuGetApiKey ${{ secrets.PSGALLERY_API_KEY }}" From 48452ce686e0eeee27da588540dca4568a9711a3 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Fri, 23 Jul 2021 16:15:34 -0400 Subject: [PATCH 26/68] Update deploy.ps1 docs --- deploy.ps1 | 57 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/deploy.ps1 b/deploy.ps1 index 1f090a9..5a0a379 100644 --- a/deploy.ps1 +++ b/deploy.ps1 @@ -1,18 +1,31 @@ <# .SYNOPSIS - A brief description of the Invoke-deploy_ps1 file. - + Concatenate files into single PSM1 and PSD1 files + .DESCRIPTION - A description of the file. + Concatenate all ps1 files in the Functions directory, plus the root PSM1, + into a single PSM1 file in the NetboxPS directory. + By default, this script will increment version by 0.0.1 + .PARAMETER SkipVersion - A description of the SkipVersion parameter. - + Do not increment the version. + .PARAMETER VersionIncrease - A description of the VersionIncrease parameter. - + Increase the version by a user defined amount + .PARAMETER NewVersion - A description of the NewVersion parameter. + Override the new version with this version + + .EXAMPLE + Use all defaults and concatenate all files + + .\deploy.ps1 + + .EXAMPLE + Increment the version by 0.2.0. Given version 1.2.0, the resulting version will be 1.4.0 + + .\deploy.ps1 -VersionIncrease 0.2.0 .NOTES =========================================================================== @@ -28,10 +41,10 @@ param ( [Parameter(ParameterSetName = 'SkipVersion')] [switch]$SkipVersion, - + [Parameter(ParameterSetName = 'IncreaseVersion')] [version]$VersionIncrease = "0.0.1", - + [Parameter(ParameterSetName = 'SetVersion')] [version]$NewVersion ) @@ -55,14 +68,14 @@ $Counter = 0 Write-Host "Concatenating [$($PS1Files.Count)] PS1 files from $FunctionPath" foreach ($File in $PS1Files) { $Counter++ - + try { Write-Host (" Adding file {0:D2}/{1:D2}: $($File.Name)" -f $Counter, $PS1Files.Count) - + "`r`n#region File $($File.Name)`r`n" | Out-File -FilePath $ConcatenatedFilePath -Encoding utf8 -Append -ErrorAction Stop - + Get-Content $File.FullName -Encoding UTF8 -ErrorAction Stop | Out-File -FilePath $ConcatenatedFilePath -Encoding utf8 -Append -ErrorAction Stop - + "`r`n#endregion" | Out-File -FilePath $ConcatenatedFilePath -Encoding utf8 -Append -ErrorAction Stop } catch { Write-Host "FAILED TO WRITE CONCATENATED FILE: $($_.Exception.Message): $($_.TargetObject)" -ForegroundColor Red @@ -85,30 +98,30 @@ switch ($PSCmdlet.ParameterSetName) { "SkipVersion" { # Dont do anything with the PSD Write-Host " Skipping version update, maintaining version [$CurrentVersion]" - + break } - + "IncreaseVersion" { # Calculate the new version [version]$NewVersion = "{0}.{1}.{2}" -f ($CurrentVersion.Major + $VersionIncrease.Major), ($CurrentVersion.Minor + $VersionIncrease.Minor), ($CurrentVersion.Build + $VersionIncrease.Build) - + Write-Host " Updating version in PSD1 from [$CurrentVersion] to [$NewVersion]" - + # Replace the version number in the content #$PSDContent -replace $CurrentVersion, $NewVersion | Out-File $PSScriptRoot\$ModuleName.psd1 -Encoding UTF8 Update-ModuleManifest -Path "$PSScriptRoot\$ModuleName.psd1" -ModuleVersion $NewVersion - + break } - + "SetVersion" { Write-Host " Updating version in PSD1 from [$CurrentVersion] to [$NewVersion]" - + # Replace the version number in the content #$PSDContent -replace $CurrentVersion, $NewVersion | Out-File $PSScriptRoot\$ModuleName.psd1 -Encoding UTF8 Update-ModuleManifest -Path "$PSScriptRoot\$ModuleName.psd1" -ModuleVersion $NewVersion - + break } } From f9fc02756c50e47705ef5815ba92c5c9c08c98c9 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Fri, 23 Jul 2021 16:15:46 -0400 Subject: [PATCH 27/68] Update readme --- README.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a2e8ee6..5763fc1 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,29 @@ # Disclaimer This module is beta. Use it at your own risk. I have only added functions as I have needed them, so not everything is available. +All functions are exported at the moment, including internal/private functions. + # Description This module is a wrapper for the [Netbox](https://github.com/netbox-community/netbox) API. # Usage 1. Install module from the `netboxPS` folder 2. Import module -3. Connect to an API endpoint by using `Connect-NetboxAPI -Hostname netbox.example.com` \ No newline at end of file +3. Connect to an API endpoint by using `Connect-NetboxAPI -Hostname netbox.example.com` + +# Notes +I started this project years ago with Powershell Studio using the built in deployment methods, learning Git, and learning PS best practices. So please forgive any "obvious" mistakes 😅 +Over time I have had to adjust my methods for deployment... change the design of functions, and refactor code as I learn new and better things. + +This was built out of a need at my job to interact with Netbox for automation. Only recently has it become a "public" project with other collaborators (which I truly appreciate!). +I have done my best to ensure each function does exactly one thing according to the API. + +I will do my best to keep up, but please understand it is given attention as I can at work. As time permits, I will open issues for TODOs for things I have wanted to do for a while, just haven't had time or enough "need" to do them. + +# Contributing +- Follow [Powershell Practice and Style Guidelines](https://poshcode.gitbook.io/powershell-practice-and-style/) when writing code +- Use discussions for general questions +- Open issues for bug fixes or enhancements +- Submit all pull requests against the dev branch + +I am always open to suggestions for improvement with reasons and data to back up the suggestion. \ No newline at end of file From c11680a20e5473912b316c8431578cef7ed2c574 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Fri, 23 Jul 2021 16:16:13 -0400 Subject: [PATCH 28/68] Remove unused files --- Functions/Circuits/Circuits.ps1 | 14 ------------- Functions/Tenancy/Tenancy.ps1 | 36 --------------------------------- 2 files changed, 50 deletions(-) delete mode 100644 Functions/Circuits/Circuits.ps1 delete mode 100644 Functions/Tenancy/Tenancy.ps1 diff --git a/Functions/Circuits/Circuits.ps1 b/Functions/Circuits/Circuits.ps1 deleted file mode 100644 index 6b2af57..0000000 --- a/Functions/Circuits/Circuits.ps1 +++ /dev/null @@ -1,14 +0,0 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.148 - Created on: 2/28/2018 4:06 PM - Created by: Ben Claussen - Organization: NEOnet - Filename: Circuits.ps1 - =========================================================================== - .DESCRIPTION - Circuit object functions -#> - - diff --git a/Functions/Tenancy/Tenancy.ps1 b/Functions/Tenancy/Tenancy.ps1 deleted file mode 100644 index ef5e187..0000000 --- a/Functions/Tenancy/Tenancy.ps1 +++ /dev/null @@ -1,36 +0,0 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.152 - Created on: 5/29/2018 1:45 PM - Created by: Ben Claussen - Organization: NEOnet - Filename: Tenancy.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - - - -#region GET commands - - - -#endregion GET commands - - -#region SET commands - -#endregion SET commands - - -#region ADD/NEW commands - -#endregion ADD/NEW commands - - -#region REMOVE commands - -#endregion REMOVE commands \ No newline at end of file From 30ae377493a00ea7b0533098039ed52d88efa63f Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Fri, 23 Jul 2021 16:19:03 -0400 Subject: [PATCH 29/68] Increment version to 1.5.0 --- NetboxPS.psd1 | 2 +- NetboxPS/NetboxPS.psd1 | 2 +- NetboxPS/NetboxPS.psm1 | 397 +++++++++++++++++++---------------------- 3 files changed, 185 insertions(+), 216 deletions(-) diff --git a/NetboxPS.psd1 b/NetboxPS.psd1 index a6b4a3f..3cb6799 100644 --- a/NetboxPS.psd1 +++ b/NetboxPS.psd1 @@ -12,7 +12,7 @@ RootModule = 'NetboxPS.psm1' # Version number of this module. -ModuleVersion = '1.4.1' +ModuleVersion = '1.5.0' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/NetboxPS/NetboxPS.psd1 b/NetboxPS/NetboxPS.psd1 index a6b4a3f..3cb6799 100644 --- a/NetboxPS/NetboxPS.psd1 +++ b/NetboxPS/NetboxPS.psd1 @@ -12,7 +12,7 @@ RootModule = 'NetboxPS.psm1' # Version number of this module. -ModuleVersion = '1.4.1' +ModuleVersion = '1.5.0' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/NetboxPS/NetboxPS.psm1 b/NetboxPS/NetboxPS.psm1 index c83401d..d429bbb 100644 --- a/NetboxPS/NetboxPS.psm1 +++ b/NetboxPS/NetboxPS.psm1 @@ -106,7 +106,7 @@ function Add-NetboxDCIMInterface { function Add-NetboxDCIMInterfaceConnection { -<# + <# .SYNOPSIS Create a new connection between two interfaces @@ -147,8 +147,8 @@ function Add-NetboxDCIMInterfaceConnection { } # Verify if both Interfaces exist - $I_A = Get-NetboxDCIMInterface -Id $Interface_A -ErrorAction Stop - $I_B = Get-NetboxDCIMInterface -Id $Interface_B -ErrorAction Stop + Get-NetboxDCIMInterface -Id $Interface_A -ErrorAction Stop | Out-null + Get-NetboxDCIMInterface -Id $Interface_B -ErrorAction Stop | Out-null $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections')) @@ -428,25 +428,6 @@ function CheckNetboxIsConnected { } } -#endregion - -#region File Circuits.ps1 - -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.148 - Created on: 2/28/2018 4:06 PM - Created by: Ben Claussen - Organization: NEOnet - Filename: Circuits.ps1 - =========================================================================== - .DESCRIPTION - Circuit object functions -#> - - - #endregion #region File Clear-NetboxCredential.ps1 @@ -457,7 +438,7 @@ function Clear-NetboxCredential { ( [switch]$Force ) - + if ($Force -or ($PSCmdlet.ShouldProcess('Netbox Credentials', 'Clear'))) { $script:NetboxConfig.Credential = $null } @@ -829,7 +810,7 @@ function GetNetboxAPIErrorBody { function Get-NetboxCircuit { -<# + <# .SYNOPSIS Gets one or more circuits @@ -921,28 +902,30 @@ function Get-NetboxCircuit { [switch]$Raw ) - switch ($PSCmdlet.ParameterSetName) { - 'ById' { - foreach ($i in $ID) { - $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits', $i)) + process { + switch ($PSCmdlet.ParameterSetName) { + 'ById' { + foreach ($i in $ID) { + $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits', $i)) - $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id" + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id" + + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters + + InvokeNetboxRequest -URI $URI -Raw:$Raw + } + } + + default { + $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits')) + + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters InvokeNetboxRequest -URI $URI -Raw:$Raw } } - - default { - $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits')) - - $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters - - $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - - InvokeNetboxRequest -URI $URI -Raw:$Raw - } } } @@ -1291,17 +1274,19 @@ function Get-NetboxDCIMDevice { #endregion Parameters - if ($null -ne $Status) { - $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus + process { + if ($null -ne $Status) { + $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus + } + + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices')) + + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw' + + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters + + InvokeNetboxRequest -URI $URI -Raw:$Raw } - - $Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices')) - - $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw' - - $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - - InvokeNetboxRequest -URI $URI -Raw:$Raw } #endregion @@ -1490,17 +1475,19 @@ function Get-NetboxDCIMInterface { [switch]$Raw ) - if ($null -ne $Form_Factor) { - $PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor + process { + if ($null -ne $Form_Factor) { + $PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor + } + + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces')) + + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters + + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters + + InvokeNetboxRequest -URI $URI -Raw:$Raw } - - $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces')) - - $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters - - $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - - InvokeNetboxRequest -URI $URI -Raw:$Raw } #endregion @@ -1709,28 +1696,30 @@ function Get-NetboxDCIMSite { [switch]$Raw ) - switch ($PSCmdlet.ParameterSetName) { - 'ById' { - foreach ($Site_ID in $ID) { - $Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites', $Site_Id)) + process { + switch ($PSCmdlet.ParameterSetName) { + 'ById' { + foreach ($Site_ID in $ID) { + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites', $Site_Id)) - $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id" + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id" + + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters + + InvokeNetboxRequest -URI $URI -Raw:$Raw + } + } + + default { + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites')) + + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters InvokeNetboxRequest -URI $URI -Raw:$Raw } } - - default { - $Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites')) - - $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters - - $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - - InvokeNetboxRequest -URI $URI -Raw:$Raw - } } } @@ -2826,7 +2815,7 @@ function Get-NetboxVirtualizationClusterGroup { function Get-NetboxVirtualMachine { -<# + <# .SYNOPSIS Obtains virtual machines from Netbox. @@ -2954,17 +2943,19 @@ function Get-NetboxVirtualMachine { [switch]$Raw ) - if ($null -ne $Status) { - $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus + process { + if ($null -ne $Status) { + $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus + } + + $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines')) + + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters + + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters + + InvokeNetboxRequest -URI $uri -Raw:$Raw } - - $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines')) - - $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - - $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - - InvokeNetboxRequest -URI $uri -Raw:$Raw } #endregion @@ -2986,7 +2977,7 @@ function Get-NetboxVirtualMachine { function Get-NetboxVirtualMachineInterface { -<# + <# .SYNOPSIS Gets VM interfaces @@ -3057,13 +3048,15 @@ function Get-NetboxVirtualMachineInterface { [switch]$Raw ) - $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces')) + process { + $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces')) - $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - InvokeNetboxRequest -URI $uri -Raw:$Raw + InvokeNetboxRequest -URI $uri -Raw:$Raw + } } #endregion @@ -3199,12 +3192,12 @@ function InvokeNetboxRequest { function New-NetboxCircuit { [CmdletBinding(ConfirmImpact = 'Low', - SupportsShouldProcess = $true)] + SupportsShouldProcess = $true)] [OutputType([pscustomobject])] param ( [Parameter(Mandatory = $true, - ValueFromPipelineByPropertyName = $true)] + ValueFromPipelineByPropertyName = $true)] [string]$CID, [Parameter(Mandatory = $true)] @@ -3238,15 +3231,17 @@ function New-NetboxCircuit { [switch]$Raw ) - $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits')) - $Method = 'POST' + process { + $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits')) + $Method = 'POST' - $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - $URI = BuildNewURI -Segments $URIComponents.Segments + $URI = BuildNewURI -Segments $URIComponents.Segments - if ($Force -or $PSCmdlet.ShouldProcess($CID, 'Create new circuit')) { - InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw + if ($Force -or $PSCmdlet.ShouldProcess($CID, 'Create new circuit')) { + InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw + } } } @@ -3269,7 +3264,8 @@ function New-NetboxCircuit { function New-NetboxDCIMDevice { - [CmdletBinding()] + [CmdletBinding(ConfirmImpact = 'low', + SupportsShouldProcess = $true)] [OutputType([pscustomobject])] #region Parameters param @@ -3320,21 +3316,21 @@ function New-NetboxDCIMDevice { ) #endregion Parameters -# if ($null -ne $Device_Role) { -# # Validate device role? -# } + # if ($null -ne $Device_Role) { + # # Validate device role? + # } -# if ($null -ne $Device_Type) { -# # Validate device type? -# } + # if ($null -ne $Device_Type) { + # # Validate device type? + # } -# if ($null -ne $Status) { -# $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus -# } + # if ($null -ne $Status) { + # $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus + # } -# if ($null -ne $Face) { -# $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace -# } + # if ($null -ne $Face) { + # $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace + # } $Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices')) @@ -3342,7 +3338,9 @@ function New-NetboxDCIMDevice { $URI = BuildNewURI -Segments $URIComponents.Segments - InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST + if ($PSCmdlet.ShouldProcess($Name, 'Create new Device')) { + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST + } } #endregion @@ -3350,16 +3348,16 @@ function New-NetboxDCIMDevice { #region File New-NetboxIPAMAddress.ps1 <# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 11:51 - Created by: Claussen - Organization: NEOnet - Filename: New-NetboxIPAMAddress.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. + .NOTES + =========================================================================== + Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 + Created on: 3/19/2020 11:51 + Created by: Claussen + Organization: NEOnet + Filename: New-NetboxIPAMAddress.ps1 + =========================================================================== + .DESCRIPTION + A description of the file. #> @@ -3401,14 +3399,19 @@ function New-NetboxIPAMAddress { .PARAMETER Dns_name DNS Name of IP address (example : netbox.example.com) - .PARAMETER Force - Do not prompt for confirmation to create IP. + .PARAMETER Assigned_Object_Type + Assigned Object Type dcim.interface or virtualization.vminterface + + .PARAMETER Assigned_Object_Id + Assigned Object ID .PARAMETER Raw Return raw results from API service .EXAMPLE - PS C:\> Create-NetboxIPAMAddress + New-NetboxIPAMAddress -Address 192.0.2.1/32 + + Add new IP Address 192.0.2.1/32 with status active .NOTES Additional information about the function. @@ -3441,7 +3444,10 @@ function New-NetboxIPAMAddress { [string]$Dns_name, - [switch]$Force, + [ValidateSet('dcim.interface', 'virtualization.vminterface', IgnoreCase = $true)] + [string]$Assigned_Object_Type, + + [int]$Assigned_Object_Id, [switch]$Raw ) @@ -3450,22 +3456,11 @@ function New-NetboxIPAMAddress { $Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses')) $Method = 'POST' - # # Value validation - # $ModelDefinition = GetModelDefinitionFromURIPath -Segments $Segments -Method $Method - # $EnumProperties = GetModelEnumProperties -ModelDefinition $ModelDefinition - # - # foreach ($Property in $EnumProperties.Keys) { - # if ($PSBoundParameters.ContainsKey($Property)) { - # Write-Verbose "Validating property [$Property] with value [$($PSBoundParameters.$Property)]" - # $PSBoundParameters.$Property = ValidateValue -ModelDefinition $ModelDefinition -Property $Property -ProvidedValue $PSBoundParameters.$Property - # } - # } - # $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters $URI = BuildNewURI -Segments $URIComponents.Segments - if ($Force -or $PSCmdlet.ShouldProcess($Address, 'Create new IP address')) { + if ($PSCmdlet.ShouldProcess($Address, 'Create new IP address')) { InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw } } @@ -3495,6 +3490,8 @@ function New-NetboxIPAMAddress { function New-NetboxIPAMPrefix { + [CmdletBinding(ConfirmImpact = 'low', + SupportsShouldProcess = $true)] [CmdletBinding()] param ( @@ -3522,7 +3519,7 @@ function New-NetboxIPAMPrefix { [switch]$Raw ) -# $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -PrefixStatus + # $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -PrefixStatus <# # As of 2018/10/18, this does not appear to be a validated IPAM choice @@ -3537,7 +3534,9 @@ function New-NetboxIPAMPrefix { $URI = BuildNewURI -Segments $URIComponents.Segments - InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw + if ($PSCmdlet.ShouldProcess($Prefix, 'Create new Prefix')) { + InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw + } } #endregion @@ -3545,7 +3544,7 @@ function New-NetboxIPAMPrefix { #region File New-NetboxIPAMVLAN.ps1 function New-NetboxIPAMVLAN { -<# + <# .SYNOPSIS Create a new VLAN @@ -3586,7 +3585,8 @@ function New-NetboxIPAMVLAN { Additional information about the function. #> - [CmdletBinding()] + [CmdletBinding(ConfirmImpact = 'low', + SupportsShouldProcess = $true)] [OutputType([pscustomobject])] param ( @@ -3609,11 +3609,11 @@ function New-NetboxIPAMVLAN { [switch]$Raw ) -# $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus + # $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus -# if ($null -ne $Role) { -# $PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole -# } + # if ($null -ne $Role) { + # $PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole + # } $segments = [System.Collections.ArrayList]::new(@('ipam', 'vlans')) @@ -3621,7 +3621,9 @@ function New-NetboxIPAMVLAN { $URI = BuildNewURI -Segments $URIComponents.Segments - InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw + if ($PSCmdlet.ShouldProcess($nae, 'Create new Vlan $($vid)')) { + InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw + } } #endregion @@ -3643,7 +3645,8 @@ function New-NetboxIPAMVLAN { function New-NetboxVirtualMachine { - [CmdletBinding()] + [CmdletBinding(ConfirmImpact = 'low', + SupportsShouldProcess = $true)] [OutputType([pscustomobject])] param ( @@ -3676,12 +3679,12 @@ function New-NetboxVirtualMachine { [string]$Comments ) -# $ModelDefinition = $script:NetboxConfig.APIDefinition.definitions.WritableVirtualMachineWithConfigContext + # $ModelDefinition = $script:NetboxConfig.APIDefinition.definitions.WritableVirtualMachineWithConfigContext -# # Validate the status against the APIDefinition -# if ($ModelDefinition.properties.status.enum -inotcontains $Status) { -# throw ("Invalid value [] for Status. Must be one of []" -f $Status, ($ModelDefinition.properties.status.enum -join ', ')) -# } + # # Validate the status against the APIDefinition + # if ($ModelDefinition.properties.status.enum -inotcontains $Status) { + # throw ("Invalid value [] for Status. Must be one of []" -f $Status, ($ModelDefinition.properties.status.enum -join ', ')) + # } #$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus @@ -3691,7 +3694,9 @@ function New-NetboxVirtualMachine { $URI = BuildNewURI -Segments $URIComponents.Segments - InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters + if ($PSCmdlet.ShouldProcess($name, 'Create new Virtual Machine')) { + InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters + } } @@ -4206,12 +4211,13 @@ function Set-NetboxDCIMDevice { function Set-NetboxDCIMInterface { - [CmdletBinding()] + [CmdletBinding(ConfirmImpact = 'Medium', + SupportsShouldProcess = $true)] [OutputType([pscustomobject])] param ( [Parameter(Mandatory = $true, - ValueFromPipelineByPropertyName = $true)] + ValueFromPipelineByPropertyName = $true)] [uint16[]]$Id, [uint16]$Device, @@ -4243,9 +4249,9 @@ function Set-NetboxDCIMInterface { ) begin { -# if ($null -ne $Form_Factor) { -# $PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor -# } + # if ($null -ne $Form_Factor) { + # $PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor + # } if (-not [System.String]::IsNullOrWhiteSpace($Mode)) { $PSBoundParameters.Mode = switch ($Mode) { @@ -4281,7 +4287,9 @@ function Set-NetboxDCIMInterface { $URI = BuildNewURI -Segments $Segments - InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH + if ($Force -or $pscmdlet.ShouldProcess("Interface ID $($CurrentInterface.Id)", "Set")) { + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH + } } } @@ -4735,11 +4743,11 @@ Function Set-NetboxUntrustedSSL { function Set-NetboxVirtualMachine { [CmdletBinding(ConfirmImpact = 'Medium', - SupportsShouldProcess = $true)] + SupportsShouldProcess = $true)] param ( [Parameter(Mandatory = $true, - ValueFromPipelineByPropertyName = $true)] + ValueFromPipelineByPropertyName = $true)] [uint16]$Id, [string]$Name, @@ -4771,24 +4779,26 @@ function Set-NetboxVirtualMachine { [switch]$Force ) -# if ($null -ne $Status) { -# $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus -# } + # if ($null -ne $Status) { + # $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus + # } - $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines', $Id)) + process { + $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines', $Id)) - Write-Verbose "Obtaining VM from ID $Id" + Write-Verbose "Obtaining VM from ID $Id" - #$CurrentVM = Get-NetboxVirtualMachine -Id $Id -ErrorAction Stop + #$CurrentVM = Get-NetboxVirtualMachine -Id $Id -ErrorAction Stop - Write-Verbose "Finished obtaining VM" + Write-Verbose "Finished obtaining VM" - if ($Force -or $pscmdlet.ShouldProcess($ID, "Set properties on VM ID")) { - $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force' + if ($Force -or $pscmdlet.ShouldProcess($ID, "Set properties on VM ID")) { + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force' - $URI = BuildNewURI -Segments $URIComponents.Segments + $URI = BuildNewURI -Segments $URIComponents.Segments - InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH + } } } @@ -4889,47 +4899,6 @@ function SetupNetboxConfigVariable { #endregion -#region File Tenancy.ps1 - -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.152 - Created on: 5/29/2018 1:45 PM - Created by: Ben Claussen - Organization: NEOnet - Filename: Tenancy.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - - - -#region GET commands - - - -#endregion GET commands - - -#region SET commands - -#endregion SET commands - - -#region ADD/NEW commands - -#endregion ADD/NEW commands - - -#region REMOVE commands - -#endregion REMOVE commands - -#endregion - #region File ThrowNetboxRESTError.ps1 <# From e162c059006d665f9ea9edd584e5bc3c5e948988 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Fri, 10 Sep 2021 17:31:15 +0200 Subject: [PATCH 30/68] Fix Publish on PSGallery (with PS Core) (#24) * Connect: Add System.Web to Type (Assembly) for PS 5.0 * NetboxPS(.psd1): Remove Required Assemblies (System.web) requirement --- Functions/Setup/Connect-NetboxAPI.ps1 | 2 ++ NetboxPS.psd1 | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Functions/Setup/Connect-NetboxAPI.ps1 b/Functions/Setup/Connect-NetboxAPI.ps1 index b012a0f..5626dfb 100644 --- a/Functions/Setup/Connect-NetboxAPI.ps1 +++ b/Functions/Setup/Connect-NetboxAPI.ps1 @@ -85,6 +85,8 @@ #for PowerShell (<=) 5 (Desktop), Enable TLS 1.1, 1.2 and Disable SSL chain trust if ("Desktop" -eq $PSVersionTable.PsEdition) { + #Add System.web (Need for ParseQueryString) + Add-Type -AssemblyName System.Web #Enable TLS 1.1 and 1.2 Set-NetboxCipherSSL if ($SkipCertificateCheck) { diff --git a/NetboxPS.psd1 b/NetboxPS.psd1 index 3cb6799..d2ce728 100644 --- a/NetboxPS.psd1 +++ b/NetboxPS.psd1 @@ -54,7 +54,7 @@ CLRVersion = '2.0.50727' # RequiredModules = @() # Assemblies that must be loaded prior to importing this module -RequiredAssemblies = 'System.Web' +#RequiredAssemblies = '' # Script files (.ps1) that are run in the caller's environment prior to importing this module. # ScriptsToProcess = @() From e8a5fdf15d333070bd5f5a986d59ddb5290c3474 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Fri, 10 Sep 2021 17:34:37 +0200 Subject: [PATCH 31/68] Enhance (DCIM) Site (#25) * Site(DCIM): Fix Get without parameter * Site(DCIM): Fix indent (use 4 spaces for header) * Site(DCIM): Add New-NetboxDCIMSite for Add DCIM Site * Site(DCIM): Add Remove-NetboxDCIMSite for Remove DCIM Site --- Functions/DCIM/Sites/Get-NetboxDCIMSite.ps1 | 23 +++-- Functions/DCIM/Sites/New-NetboxDCIMSite.ps1 | 86 +++++++++++++++++++ .../DCIM/Sites/Remove-NetboxDCIMSite.ps1 | 64 ++++++++++++++ 3 files changed, 161 insertions(+), 12 deletions(-) create mode 100644 Functions/DCIM/Sites/New-NetboxDCIMSite.ps1 create mode 100644 Functions/DCIM/Sites/Remove-NetboxDCIMSite.ps1 diff --git a/Functions/DCIM/Sites/Get-NetboxDCIMSite.ps1 b/Functions/DCIM/Sites/Get-NetboxDCIMSite.ps1 index 90c6e2a..963e089 100644 --- a/Functions/DCIM/Sites/Get-NetboxDCIMSite.ps1 +++ b/Functions/DCIM/Sites/Get-NetboxDCIMSite.ps1 @@ -1,20 +1,20 @@ <# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 - Created on: 2020-10-02 15:52 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxDCIMSite.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. + .NOTES + =========================================================================== + Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 + Created on: 2020-10-02 15:52 + Created by: Claussen + Organization: NEOnet + Filename: Get-NetboxDCIMSite.ps1 + =========================================================================== + .DESCRIPTION + A description of the file. #> function Get-NetboxDCIMSite { - [CmdletBinding()] + [CmdletBinding(DefaultParameterSetName = 'Query')] [OutputType([pscustomobject])] param ( @@ -107,4 +107,3 @@ function Get-NetboxDCIMSite { } } } - diff --git a/Functions/DCIM/Sites/New-NetboxDCIMSite.ps1 b/Functions/DCIM/Sites/New-NetboxDCIMSite.ps1 new file mode 100644 index 0000000..38e5ac3 --- /dev/null +++ b/Functions/DCIM/Sites/New-NetboxDCIMSite.ps1 @@ -0,0 +1,86 @@ +<# + .NOTES + =========================================================================== + Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 + Created on: 2020-10-02 15:52 + Created by: Claussen + Organization: NEOnet + Filename: New-NetboxDCIMSite.ps1 + =========================================================================== + .DESCRIPTION + A description of the file. +#> + + + +function New-NetboxDCIMSite { + <# + .SYNOPSIS + Create a new Site to Netbox + + .DESCRIPTION + Create a new Site to Netbox + + .EXAMPLE + New-NetboxDCIMSite -name MySite + + Add new Site MySite on Netbox + + #> + + [CmdletBinding(ConfirmImpact = 'Low', + SupportsShouldProcess = $true)] + [OutputType([pscustomobject])] + param + ( + [Parameter(Mandatory = $true)] + [string]$Name, + + [string]$Slug, + + [string]$Facility, + + [uint32]$ASN, + + [decimal]$Latitude, + + [decimal]$Longitude, + + [string]$Contact_Name, + + [string]$Contact_Phone, + + [string]$Contact_Email, + + [int]$Tenant_Group, + + [int]$Tenant, + + [string]$Status, + + [uint32]$Region, + + [string]$Description, + + [string]$Comments, + + [switch]$Raw + ) + + process { + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites')) + $Method = 'POST' + + if (-not $PSBoundParameters.ContainsKey('slug')) { + $PSBoundParameters.Add('slug', $name) + } + + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters + + $URI = BuildNewURI -Segments $URIComponents.Segments + + if ($PSCmdlet.ShouldProcess($name, 'Create new Site')) { + InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw + } + } +} diff --git a/Functions/DCIM/Sites/Remove-NetboxDCIMSite.ps1 b/Functions/DCIM/Sites/Remove-NetboxDCIMSite.ps1 new file mode 100644 index 0000000..a87737c --- /dev/null +++ b/Functions/DCIM/Sites/Remove-NetboxDCIMSite.ps1 @@ -0,0 +1,64 @@ +<# + .NOTES + =========================================================================== + Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 + Created on: 2020-10-02 15:52 + Created by: Claussen + Organization: NEOnet + Filename: New-NetboxDCIMSite.ps1 + =========================================================================== + .DESCRIPTION + A description of the file. +#> + + +function Remove-NetboxDCIMSite { + <# + .SYNOPSIS + Remove a Site + + .DESCRIPTION + Remove a DCIM Site from Netbox + + .EXAMPLE + Remove-NetboxDCIMSite -Id 1 + + Remove DCM Site with id 1 + + .EXAMPLE + Get-NetboxDCIMSite -name My Site | Remove-NetboxDCIMSite -confirm:$false + + Remove DCM Site with name My Site without confirmation + + #> + + [CmdletBinding(ConfirmImpact = 'High', + SupportsShouldProcess = $true)] + param + ( + [Parameter(Mandatory = $true, + ValueFromPipelineByPropertyName = $true)] + [uint]$Id + + ) + + begin { + + } + + process { + $CurrentSite = Get-NetboxDCIMSite -Id $Id -ErrorAction Stop + + if ($pscmdlet.ShouldProcess("$($CurrentSite.Name)/$($CurrentSite.Id)", "Remove Site")) { + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites', $CurrentSite.Id)) + + $URI = BuildNewURI -Segments $Segments + + InvokeNetboxRequest -URI $URI -Method DELETE + } + } + + end { + + } +} \ No newline at end of file From a608d6ebd7367bef4f7921ec61afc238bfc57ff7 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Fri, 10 Sep 2021 17:35:49 +0200 Subject: [PATCH 32/68] Fix PSSA deploy(.ps1) warning (#26) * Deploy: fix indent (remove trailing whitespace) * Deploy(.ps1): Remove PSSA warning about don't use Write-host * Deploy(.ps1): Remove PSSA warning unused variable false positive (it is used for ParameterSet...) --- deploy.ps1 | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/deploy.ps1 b/deploy.ps1 index 5a0a379..cb01f34 100644 --- a/deploy.ps1 +++ b/deploy.ps1 @@ -1,19 +1,19 @@ <# .SYNOPSIS Concatenate files into single PSM1 and PSD1 files - + .DESCRIPTION Concatenate all ps1 files in the Functions directory, plus the root PSM1, into a single PSM1 file in the NetboxPS directory. By default, this script will increment version by 0.0.1 - + .PARAMETER SkipVersion - Do not increment the version. - + Do not increment the version. + .PARAMETER VersionIncrease Increase the version by a user defined amount - + .PARAMETER NewVersion Override the new version with this version @@ -37,14 +37,16 @@ =========================================================================== #> [CmdletBinding(DefaultParameterSetName = 'IncreaseVersion')] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "")] param ( [Parameter(ParameterSetName = 'SkipVersion')] [switch]$SkipVersion, - + [Parameter(ParameterSetName = 'IncreaseVersion')] [version]$VersionIncrease = "0.0.1", - + [Parameter(ParameterSetName = 'SetVersion')] [version]$NewVersion ) @@ -68,14 +70,14 @@ $Counter = 0 Write-Host "Concatenating [$($PS1Files.Count)] PS1 files from $FunctionPath" foreach ($File in $PS1Files) { $Counter++ - + try { Write-Host (" Adding file {0:D2}/{1:D2}: $($File.Name)" -f $Counter, $PS1Files.Count) - + "`r`n#region File $($File.Name)`r`n" | Out-File -FilePath $ConcatenatedFilePath -Encoding utf8 -Append -ErrorAction Stop - + Get-Content $File.FullName -Encoding UTF8 -ErrorAction Stop | Out-File -FilePath $ConcatenatedFilePath -Encoding utf8 -Append -ErrorAction Stop - + "`r`n#endregion" | Out-File -FilePath $ConcatenatedFilePath -Encoding utf8 -Append -ErrorAction Stop } catch { Write-Host "FAILED TO WRITE CONCATENATED FILE: $($_.Exception.Message): $($_.TargetObject)" -ForegroundColor Red @@ -98,30 +100,30 @@ switch ($PSCmdlet.ParameterSetName) { "SkipVersion" { # Dont do anything with the PSD Write-Host " Skipping version update, maintaining version [$CurrentVersion]" - + break } - + "IncreaseVersion" { # Calculate the new version [version]$NewVersion = "{0}.{1}.{2}" -f ($CurrentVersion.Major + $VersionIncrease.Major), ($CurrentVersion.Minor + $VersionIncrease.Minor), ($CurrentVersion.Build + $VersionIncrease.Build) - + Write-Host " Updating version in PSD1 from [$CurrentVersion] to [$NewVersion]" - + # Replace the version number in the content #$PSDContent -replace $CurrentVersion, $NewVersion | Out-File $PSScriptRoot\$ModuleName.psd1 -Encoding UTF8 Update-ModuleManifest -Path "$PSScriptRoot\$ModuleName.psd1" -ModuleVersion $NewVersion - + break } - + "SetVersion" { Write-Host " Updating version in PSD1 from [$CurrentVersion] to [$NewVersion]" - + # Replace the version number in the content #$PSDContent -replace $CurrentVersion, $NewVersion | Out-File $PSScriptRoot\$ModuleName.psd1 -Encoding UTF8 Update-ModuleManifest -Path "$PSScriptRoot\$ModuleName.psd1" -ModuleVersion $NewVersion - + break } } From 7edbae953f0b58b4c1d213ff04ceed25ddb20bc5 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Fri, 10 Sep 2021 17:38:00 +0200 Subject: [PATCH 33/68] Tests: Fix PSSA (#27) * Tests: fix indent/align (with Visual Formatter Code) * Tests: Suppress warning about use ConvertToSecureString... * Setup(Tests): fix PSSA about unused variable --- Tests/DCIM.Devices.Tests.ps1 | 16 ++++++++++------ Tests/DCIM.Interfaces.Tests.ps1 | 24 ++++++++++++++---------- Tests/DCIM.Platforms.Tests.ps1 | 14 +++++++++----- Tests/Helpers.Tests.ps1 | 28 ++++++++++++++++------------ Tests/IPAM.Tests.ps1 | 18 +++++++++++------- Tests/Setup.Tests.ps1 | 6 +++++- Tests/Virtualization.Tests.ps1 | 26 +++++++++++++++----------- 7 files changed, 80 insertions(+), 52 deletions(-) diff --git a/Tests/DCIM.Devices.Tests.ps1 b/Tests/DCIM.Devices.Tests.ps1 index 5af9b8e..b3505c3 100644 --- a/Tests/DCIM.Devices.Tests.ps1 +++ b/Tests/DCIM.Devices.Tests.ps1 @@ -11,6 +11,10 @@ DCIM tests. #> +[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] +param +( +) Import-Module Pester Remove-Module NetboxPS -Force -ErrorAction SilentlyContinue @@ -28,12 +32,12 @@ Describe -Name "DCIM Devices Tests" -Tag 'DCIM', 'Devices' -Fixture { Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith { # Return a hashtable of the items we would normally pass to Invoke-RestMethod return [ordered]@{ - 'Method' = $Method - 'Uri' = $Uri - 'Headers' = $Headers - 'Timeout' = $Timeout + 'Method' = $Method + 'Uri' = $Uri + 'Headers' = $Headers + 'Timeout' = $Timeout 'ContentType' = $ContentType - 'Body' = $Body + 'Body' = $Body } } @@ -363,7 +367,7 @@ Describe -Name "DCIM Devices Tests" -Tag 'DCIM', 'Devices' -Fixture { Mock -CommandName "Get-NetboxDCIMDevice" -ModuleName NetboxPS -MockWith { return [pscustomobject]@{ - 'Id' = $Id + 'Id' = $Id 'Name' = $Name } } diff --git a/Tests/DCIM.Interfaces.Tests.ps1 b/Tests/DCIM.Interfaces.Tests.ps1 index 5499ce7..2c268f9 100644 --- a/Tests/DCIM.Interfaces.Tests.ps1 +++ b/Tests/DCIM.Interfaces.Tests.ps1 @@ -11,6 +11,10 @@ A description of the file. #> +[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] +param +( +) Import-Module Pester Remove-Module NetboxPS -Force -ErrorAction SilentlyContinue @@ -28,12 +32,12 @@ Describe -Name "DCIM Interfaces Tests" -Tag 'DCIM', 'Interfaces' -Fixture { Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith { # Return a hashtable of the items we would normally pass to Invoke-RestMethod return [ordered]@{ - 'Method' = $Method - 'Uri' = $Uri - 'Headers' = $Headers - 'Timeout' = $Timeout + 'Method' = $Method + 'Uri' = $Uri + 'Headers' = $Headers + 'Timeout' = $Timeout 'ContentType' = $ContentType - 'Body' = $Body + 'Body' = $Body } } @@ -139,13 +143,13 @@ Describe -Name "DCIM Interfaces Tests" -Tag 'DCIM', 'Interfaces' -Fixture { It "Should add an interface to a device with lots of properties" { $paramAddNetboxDCIMInterface = @{ - Device = 123 - Name = "TestInterface" + Device = 123 + Name = "TestInterface" Form_Factor = '10GBASE-T (10GE)' - MTU = 9000 - MGMT_Only = $true + MTU = 9000 + MGMT_Only = $true Description = 'Test Description' - Mode = 'Access' + Mode = 'Access' } $Result = Add-NetboxDCIMInterface @paramAddNetboxDCIMInterface diff --git a/Tests/DCIM.Platforms.Tests.ps1 b/Tests/DCIM.Platforms.Tests.ps1 index 7d2853a..752957c 100644 --- a/Tests/DCIM.Platforms.Tests.ps1 +++ b/Tests/DCIM.Platforms.Tests.ps1 @@ -11,6 +11,10 @@ A description of the file. #> +[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] +param +( +) Import-Module Pester Remove-Module NetboxPS -Force -ErrorAction SilentlyContinue @@ -28,12 +32,12 @@ Describe -Name "DCIM Platforms Tests" -Tag 'DCIM', 'platforms' -Fixture { Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith { # Return a hashtable of the items we would normally pass to Invoke-RestMethod return [ordered]@{ - 'Method' = $Method - 'Uri' = $Uri - 'Headers' = $Headers - 'Timeout' = $Timeout + 'Method' = $Method + 'Uri' = $Uri + 'Headers' = $Headers + 'Timeout' = $Timeout 'ContentType' = $ContentType - 'Body' = $Body + 'Body' = $Body } } diff --git a/Tests/Helpers.Tests.ps1 b/Tests/Helpers.Tests.ps1 index 594209d..bfbbef9 100644 --- a/Tests/Helpers.Tests.ps1 +++ b/Tests/Helpers.Tests.ps1 @@ -11,6 +11,10 @@ Helper functions Pester tests #> +[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] +param +( +) Import-Module Pester Remove-Module NetboxPS -Force -ErrorAction SilentlyContinue @@ -88,7 +92,7 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture { Context -Name "Building URI components" -Fixture { It "Should give a basic hashtable" { - $URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'param1' = 1} + $URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'param1' = 1 } $URIComponents | Should -BeOfType [hashtable] $URIComponents.Keys.Count | Should -BeExactly 2 @@ -100,7 +104,7 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture { } It "Should add a single ID parameter to the segments" { - $URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'id' = 123} + $URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'id' = 123 } $URIComponents | Should -BeOfType [hashtable] $URIComponents.Keys.Count | Should -BeExactly 2 @@ -111,7 +115,7 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture { } It "Should add multiple IDs to the parameters id__in" { - $URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'id' = "123", "456"} + $URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'id' = "123", "456" } $URIComponents | Should -BeOfType [hashtable] $URIComponents.Keys.Count | Should -BeExactly 2 @@ -123,7 +127,7 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture { } It "Should skip a particular parameter name" { - $URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'param1' = 1; 'param2' = 2} -SkipParameterByName 'param2' + $URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'param1' = 1; 'param2' = 2 } -SkipParameterByName 'param2' $URIComponents | Should -BeOfType [hashtable] $URIComponents.Keys.Count | Should -BeExactly 2 @@ -136,7 +140,7 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture { } It "Should add a query (q) parameter" { - $URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'query' = 'mytestquery'} + $URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'query' = 'mytestquery' } $URIComponents | Should -BeOfType [hashtable] $URIComponents.Keys.Count | Should -BeExactly 2 @@ -150,7 +154,7 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture { It "Should generate custom field parameters" { $URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{ 'CustomFields' = @{ - 'PRTG_Id' = 1234 + 'PRTG_Id' = 1234 'Customer_Id' = 'abc' } } @@ -170,13 +174,13 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture { Mock -CommandName 'Invoke-RestMethod' -Verifiable -MockWith { # Return an object of the items we would normally pass to Invoke-RestMethod return [pscustomobject]@{ - 'Method' = $Method - 'Uri' = $Uri - 'Headers' = $Headers - 'Timeout' = $Timeout + 'Method' = $Method + 'Uri' = $Uri + 'Headers' = $Headers + 'Timeout' = $Timeout 'ContentType' = $ContentType - 'Body' = $Body - 'results' = 'Only results' + 'Body' = $Body + 'results' = 'Only results' } } diff --git a/Tests/IPAM.Tests.ps1 b/Tests/IPAM.Tests.ps1 index 6b214e9..66a677a 100644 --- a/Tests/IPAM.Tests.ps1 +++ b/Tests/IPAM.Tests.ps1 @@ -11,6 +11,10 @@ IPAM Pester tests #> +[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] +param +( +) Import-Module Pester Remove-Module NetboxPS -Force -ErrorAction SilentlyContinue @@ -29,12 +33,12 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture { Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith { # Return a hashtable of the items we would normally pass to Invoke-RestMethod return [ordered]@{ - 'Method' = $Method - 'Uri' = $Uri - 'Headers' = $Headers - 'Timeout' = $Timeout + 'Method' = $Method + 'Uri' = $Uri + 'Headers' = $Headers + 'Timeout' = $Timeout 'ContentType' = $ContentType - 'Body' = $Body + 'Body' = $Body } } @@ -422,7 +426,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture { Mock -CommandName "Get-NetboxIPAMAddress" -ModuleName NetboxPS -MockWith { return @{ 'address' = "10.1.1.1/$Id" - 'id' = $id + 'id' = $id } } @@ -486,7 +490,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture { Mock -CommandName "Get-NetboxIPAMAddress" -ModuleName NetboxPS -MockWith { return @{ 'address' = '10.1.1.1/24' - 'id' = $id + 'id' = $id } } diff --git a/Tests/Setup.Tests.ps1 b/Tests/Setup.Tests.ps1 index dda6465..f9558d2 100644 --- a/Tests/Setup.Tests.ps1 +++ b/Tests/Setup.Tests.ps1 @@ -11,6 +11,10 @@ Setup function Pester tests #> +[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] +param +( +) Import-Module Pester Remove-Module NetboxPS -Force -ErrorAction SilentlyContinue @@ -43,7 +47,7 @@ Describe "Setup tests" -Tag 'Core', 'Setup' -Fixture { } It "Checks the set credentials" { - $Creds = Set-NetboxCredential -Token (ConvertTo-SecureString -String "faketoken" -Force -AsPlainText) + Set-NetboxCredential -Token (ConvertTo-SecureString -String "faketoken" -Force -AsPlainText) (Get-NetboxCredential).GetNetworkCredential().Password | Should -BeExactly "faketoken" } } diff --git a/Tests/Virtualization.Tests.ps1 b/Tests/Virtualization.Tests.ps1 index 0eb2682..f744a20 100644 --- a/Tests/Virtualization.Tests.ps1 +++ b/Tests/Virtualization.Tests.ps1 @@ -11,6 +11,10 @@ Virtualization Pester tests #> +[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] +param +( +) Import-Module Pester Remove-Module NetboxPS -Force -ErrorAction SilentlyContinue @@ -28,12 +32,12 @@ Describe -Name "Virtualization tests" -Tag 'Virtualization' -Fixture { Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith { # Return a hashtable of the items we would normally pass to Invoke-RestMethod return [ordered]@{ - 'Method' = $Method - 'Uri' = $Uri - 'Headers' = $Headers - 'Timeout' = $Timeout + 'Method' = $Method + 'Uri' = $Uri + 'Headers' = $Headers + 'Timeout' = $Timeout 'ContentType' = $ContentType - 'Body' = $Body + 'Body' = $Body } } @@ -365,7 +369,7 @@ Describe -Name "Virtualization tests" -Tag 'Virtualization' -Fixture { Mock -CommandName "Get-NetboxVirtualMachine" -ModuleName NetboxPS -MockWith { return [pscustomobject]@{ - 'Id' = $Id + 'Id' = $Id 'Name' = $Name } } @@ -406,7 +410,7 @@ Describe -Name "Virtualization tests" -Tag 'Virtualization' -Fixture { Mock -CommandName "Get-NetboxVirtualMachineInterface" -ModuleName NetboxPS -MockWith { return [pscustomobject]@{ - 'Id' = $Id + 'Id' = $Id 'Name' = $Name } } @@ -426,12 +430,12 @@ Describe -Name "Virtualization tests" -Tag 'Virtualization' -Fixture { It "Should set an interface to a new name, MTU, MAC address and description" { $paramSetNetboxVirtualMachineInterface = @{ - Id = 1234 - Name = 'newtestname' + Id = 1234 + Name = 'newtestname' MAC_Address = '11:22:33:44:55:66' - MTU = 9000 + MTU = 9000 Description = "Test description" - Force = $true + Force = $true } $Result = Set-NetboxVirtualMachineInterface @paramSetNetboxVirtualMachineInterface From 3e03e1e3ad8cfa1d3232cc7bc6d69c7a0093e92c Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Fri, 10 Sep 2021 12:43:34 -0400 Subject: [PATCH 34/68] Add Clear-NetboxCredential - Grants ability to clear the stored credentials in `$Netboxconfig` variable --- Functions/Setup/Clear-NetboxCredential.ps1 | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Functions/Setup/Clear-NetboxCredential.ps1 diff --git a/Functions/Setup/Clear-NetboxCredential.ps1 b/Functions/Setup/Clear-NetboxCredential.ps1 new file mode 100644 index 0000000..62109ab --- /dev/null +++ b/Functions/Setup/Clear-NetboxCredential.ps1 @@ -0,0 +1,11 @@ +function Clear-NetboxCredential { + [CmdletBinding(ConfirmImpact = 'Medium', SupportsShouldProcess = $true)] + param + ( + [switch]$Force + ) + + if ($Force -or ($PSCmdlet.ShouldProcess('Netbox Credentials', 'Clear'))) { + $script:NetboxConfig.Credential = $null + } +} \ No newline at end of file From 9dd6bc2b0ec97f631458d4b59354ad5895e92316 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Fri, 10 Sep 2021 12:44:48 -0400 Subject: [PATCH 35/68] Remove old ThrowNetboxRESTError function --- Functions/Helpers/ThrowNetboxRESTError.ps1 | 24 ---------------------- NetboxPS.psproj | 1 - 2 files changed, 25 deletions(-) delete mode 100644 Functions/Helpers/ThrowNetboxRESTError.ps1 diff --git a/Functions/Helpers/ThrowNetboxRESTError.ps1 b/Functions/Helpers/ThrowNetboxRESTError.ps1 deleted file mode 100644 index 078de90..0000000 --- a/Functions/Helpers/ThrowNetboxRESTError.ps1 +++ /dev/null @@ -1,24 +0,0 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/26/2020 14:25 - Created by: Claussen - Organization: NEOnet - Filename: ThrowNetboxRESTError.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - -function ThrowNetboxRESTError { - $uriSegments = [System.Collections.ArrayList]::new(@('fake', 'url')) - - $URIParameters = @{ - } - - $uri = BuildNewURI -Segments $uriSegments -Parameters $URIParameters - - InvokeNetboxRequest -URI $uri -Raw -} \ No newline at end of file diff --git a/NetboxPS.psproj b/NetboxPS.psproj index b71197d..c37e1db 100644 --- a/NetboxPS.psproj +++ b/NetboxPS.psproj @@ -48,7 +48,6 @@ Functions\Helpers\BuildURIComponents.ps1 Functions\Helpers\GetNetboxAPIErrorBody.ps1 Functions\Helpers\InvokeNetboxRequest.ps1 - Functions\Helpers\ThrowNetboxRESTError.ps1 Functions\Helpers\CreateEnum.ps1 Functions\Setup\Support\VerifyAPIConnectivity.ps1 Functions\Setup\Support\SetupNetboxConfigVariable.ps1 From e29299022ebd1dd264aef7ae97b6e89f685d5064 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Wed, 29 Jun 2022 07:49:55 +0200 Subject: [PATCH 36/68] Clear-NetboxCredential: Fix PSSA (trailing whitespace) --- Functions/Setup/Clear-NetboxCredential.ps1 | 4 ++-- NetboxPS/NetboxPS.psm1 | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Functions/Setup/Clear-NetboxCredential.ps1 b/Functions/Setup/Clear-NetboxCredential.ps1 index 62109ab..3decf44 100644 --- a/Functions/Setup/Clear-NetboxCredential.ps1 +++ b/Functions/Setup/Clear-NetboxCredential.ps1 @@ -4,8 +4,8 @@ ( [switch]$Force ) - + if ($Force -or ($PSCmdlet.ShouldProcess('Netbox Credentials', 'Clear'))) { $script:NetboxConfig.Credential = $null } -} \ No newline at end of file +} diff --git a/NetboxPS/NetboxPS.psm1 b/NetboxPS/NetboxPS.psm1 index d429bbb..7505c90 100644 --- a/NetboxPS/NetboxPS.psm1 +++ b/NetboxPS/NetboxPS.psm1 @@ -438,7 +438,7 @@ function Clear-NetboxCredential { ( [switch]$Force ) - + if ($Force -or ($PSCmdlet.ShouldProcess('Netbox Credentials', 'Clear'))) { $script:NetboxConfig.Credential = $null } From 7aedcf8338f61b8548516592942fb3e68a5b4a7a Mon Sep 17 00:00:00 2001 From: Ben Claussen <46791633+benclaussen1@users.noreply.github.com> Date: Mon, 28 Nov 2022 15:45:19 -0500 Subject: [PATCH 37/68] Add Site parameter and validation logic --- .../VirtualMachine/New-NetboxVirtualMachine.ps1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Functions/Virtualization/VirtualMachine/New-NetboxVirtualMachine.ps1 b/Functions/Virtualization/VirtualMachine/New-NetboxVirtualMachine.ps1 index dbab718..46945de 100644 --- a/Functions/Virtualization/VirtualMachine/New-NetboxVirtualMachine.ps1 +++ b/Functions/Virtualization/VirtualMachine/New-NetboxVirtualMachine.ps1 @@ -22,6 +22,8 @@ function New-NetboxVirtualMachine { [string]$Name, [Parameter(Mandatory = $true)] + [uint16]$Site, + [uint16]$Cluster, [uint16]$Tenant, @@ -56,6 +58,10 @@ function New-NetboxVirtualMachine { #$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus + if ($PSBoundParameters.ContainsKey('Cluster') -and (-not $PSBoundParameters.ContainsKey('Site'))) { + throw "You must specify a site ID with a cluster ID" + } + $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines')) $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters From cd0d6383e61fd4290e9bddac61920dc3c8a40297 Mon Sep 17 00:00:00 2001 From: Ben Claussen <46791633+benclaussen1@users.noreply.github.com> Date: Tue, 29 Nov 2022 11:28:11 -0500 Subject: [PATCH 38/68] Update parent parameter type to string --- Functions/IPAM/Address/Get-NetboxIPAMAddress.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Functions/IPAM/Address/Get-NetboxIPAMAddress.ps1 b/Functions/IPAM/Address/Get-NetboxIPAMAddress.ps1 index 0074030..fbc9994 100644 --- a/Functions/IPAM/Address/Get-NetboxIPAMAddress.ps1 +++ b/Functions/IPAM/Address/Get-NetboxIPAMAddress.ps1 @@ -16,7 +16,7 @@ [object]$Family, [Parameter(ParameterSetName = 'Query')] - [uint32]$Parent, + [string]$Parent, [Parameter(ParameterSetName = 'Query')] [byte]$Mask_Length, From cad361c1b4c090975fe1aee461564f6ca02274a0 Mon Sep 17 00:00:00 2001 From: Ben Claussen <46791633+benclaussen1@users.noreply.github.com> Date: Thu, 1 Dec 2022 09:46:13 -0500 Subject: [PATCH 39/68] Update deploy.ps1 with new logic --- deploy.ps1 | 71 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/deploy.ps1 b/deploy.ps1 index cb01f34..7cc3b44 100644 --- a/deploy.ps1 +++ b/deploy.ps1 @@ -17,6 +17,10 @@ .PARAMETER NewVersion Override the new version with this version + .PARAMETER Environment + A description of the Environment parameter. + .PARAMETER ResetCurrentEnvironment + A description of the ResetCurrentEnvironment parameter. .EXAMPLE Use all defaults and concatenate all files @@ -48,13 +52,17 @@ param [version]$VersionIncrease = "0.0.1", [Parameter(ParameterSetName = 'SetVersion')] - [version]$NewVersion + [version]$NewVersion, + [ValidateSet('dev', 'development', 'prod', 'production', IgnoreCase = $true)] + [string]$Environment = 'development', + [switch]$ResetCurrentEnvironment ) -Import-Module "Microsoft.PowerShell.Utility" -ErrorAction Stop Write-Host "Beginning deployment" -ForegroundColor Green +Write-Host "Importing required modules" -ForegroundColor Green +Import-Module "Microsoft.PowerShell.Utility" -ErrorAction Stop $ModuleName = 'NetboxPS' $ConcatenatedFilePath = "$PSScriptRoot\concatenated.ps1" $FunctionPath = "$PSScriptRoot\Functions" @@ -62,17 +70,17 @@ $OutputDirectory = "$PSScriptRoot\$ModuleName" $PSD1OutputPath = "$OutputDirectory\$ModuleName.psd1" $PSM1OutputPath = "$OutputDirectory\$ModuleName.psm1" -$PS1Files = Get-ChildItem $FunctionPath -Filter "*.ps1" -Recurse | Sort-Object Name +$PS1FunctionFiles = Get-ChildItem $FunctionPath -Filter "*.ps1" -Recurse | Sort-Object Name "" | Out-File -FilePath $ConcatenatedFilePath -Encoding utf8 $Counter = 0 -Write-Host "Concatenating [$($PS1Files.Count)] PS1 files from $FunctionPath" -foreach ($File in $PS1Files) { +Write-Host "Concatenating [$($PS1FunctionFiles.Count)] PS1 files from $FunctionPath" +foreach ($File in $PS1FunctionFiles) { $Counter++ try { - Write-Host (" Adding file {0:D2}/{1:D2}: $($File.Name)" -f $Counter, $PS1Files.Count) + Write-Host (" Adding file {0:D2}/{1:D2}: $($File.Name)" -f $Counter, $PS1FunctionFiles.Count) "`r`n#region File $($File.Name)`r`n" | Out-File -FilePath $ConcatenatedFilePath -Encoding utf8 -Append -ErrorAction Stop @@ -87,15 +95,33 @@ foreach ($File in $PS1Files) { "" | Out-File -FilePath $ConcatenatedFilePath -Encoding utf8 -Append +if (-not (Test-Path $OutputDirectory)) { + try { + Write-Warning "Creating path [$OutputDirectory]" + $null = New-Item -Path $OutputDirectory -ItemType Directory -Force + } catch { + throw "Failed to create output directory [$OutputDirectory]: $($_.Exception.Message)" + } +} Write-Host " Adding psm1" Get-Content "$PSScriptRoot\$ModuleName.psm1" | Out-File -FilePath $ConcatenatedFilePath -Encoding UTF8 -Append $PSDManifest = Import-PowerShellDataFile -Path "$PSScriptRoot\$ModuleName.psd1" # Get the version from the PSD1 -#[version]$CurrentVersion = [regex]::matches($PSDContent, "\s*ModuleVersion\s=\s'(\d*.\d*.\d*)'\s*").groups[1].value [version]$CurrentVersion = $PSDManifest.ModuleVersion +$UpdateModuleManifestSplat = @{ + Path = "$PSScriptRoot\$ModuleName.psd1" + ErrorAction = 'Stop' +} +if ($Environment -ilike 'dev*') { + Write-Host "Exporting all functions for development" + $UpdateModuleManifestSplat['FunctionsToExport'] = $PS1FunctionFiles.BaseName +} else { + $UpdateModuleManifestSplat['FunctionsToExport'] = ($PS1FunctionFiles.BaseName | Where-Object { $_ -like '*-*' }) +} +Write-Host "Comparing versions" switch ($PSCmdlet.ParameterSetName) { "SkipVersion" { # Dont do anything with the PSD @@ -108,35 +134,26 @@ switch ($PSCmdlet.ParameterSetName) { # Calculate the new version [version]$NewVersion = "{0}.{1}.{2}" -f ($CurrentVersion.Major + $VersionIncrease.Major), ($CurrentVersion.Minor + $VersionIncrease.Minor), ($CurrentVersion.Build + $VersionIncrease.Build) - Write-Host " Updating version in PSD1 from [$CurrentVersion] to [$NewVersion]" + Write-Host " Updating version from [$CurrentVersion] to [$NewVersion]" # Replace the version number in the content - #$PSDContent -replace $CurrentVersion, $NewVersion | Out-File $PSScriptRoot\$ModuleName.psd1 -Encoding UTF8 - Update-ModuleManifest -Path "$PSScriptRoot\$ModuleName.psd1" -ModuleVersion $NewVersion + $UpdateModuleManifestSplat['ModuleVersion'] = $NewVersion break } "SetVersion" { - Write-Host " Updating version in PSD1 from [$CurrentVersion] to [$NewVersion]" + Write-Host " Updating version from [$CurrentVersion] to [$NewVersion]" # Replace the version number in the content - #$PSDContent -replace $CurrentVersion, $NewVersion | Out-File $PSScriptRoot\$ModuleName.psd1 -Encoding UTF8 - Update-ModuleManifest -Path "$PSScriptRoot\$ModuleName.psd1" -ModuleVersion $NewVersion + $UpdateModuleManifestSplat['ModuleVersion'] = $NewVersion break } } - -if (-not (Test-Path $OutputDirectory)) { - try { - Write-Warning "Creating path [$OutputDirectory]" - $null = New-Item -Path $OutputDirectory -ItemType Directory -Force - } catch { - throw "Failed to create directory [$OutputDirectory]: $($_.Exception.Message)" - } -} +Write-Host "Updating Module Manifest" +Update-ModuleManifest @UpdateModuleManifestSplat Write-Host " Copying psd1" Copy-Item -Path "$PSScriptRoot\$ModuleName.psd1" -Destination $PSD1OutputPath -Force @@ -144,4 +161,12 @@ Copy-Item -Path "$PSScriptRoot\$ModuleName.psd1" -Destination $PSD1OutputPath -F Write-Host " Copying psm1" Copy-Item -Path $ConcatenatedFilePath -Destination $PSM1OutputPath -Force -Write-Host "Deployment complete" -ForegroundColor Green \ No newline at end of file +Write-Host "Deployment complete" -ForegroundColor Green +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 +} From c3621f237ed37dc87063459850d94ca86be22994 Mon Sep 17 00:00:00 2001 From: Claussen Date: Tue, 6 Dec 2022 13:34:52 -0500 Subject: [PATCH 40/68] Remove unnecessary file headers --- .../Circuits/Circuits/Get-NetboxCircuit.ps1 | 15 +-------------- .../Circuits/Circuits/New-NetboxCircuit.ps1 | 16 +--------------- .../Providers/Get-NetboxCircuitProvider.ps1 | 16 +--------------- .../Get-NetboxCircuitTermination.ps1 | 16 +--------------- .../Circuits/Types/Get-NetboxCircuitType.ps1 | 16 +--------------- Functions/DCIM/Devices/Get-NetboxDCIMDevice.ps1 | 15 +-------------- .../DCIM/Devices/Get-NetboxDCIMDeviceRole.ps1 | 15 +-------------- .../DCIM/Devices/Get-NetboxDCIMDeviceType.ps1 | 15 +-------------- Functions/DCIM/Devices/New-NetboxDCIMDevice.ps1 | 15 +-------------- .../DCIM/Devices/Remove-NetboxDCIMDevice.ps1 | 15 +-------------- Functions/DCIM/Devices/Set-NetboxDCIMDevice.ps1 | 15 +-------------- Functions/DCIM/Get-NetboxDCIMPlatform.ps1 | 15 +-------------- .../DCIM/Interfaces/Add-NetboxDCIMInterface.ps1 | 15 +-------------- .../Add-NetboxDCIMInterfaceConnection.ps1 | 15 +-------------- .../DCIM/Interfaces/Get-NetboxDCIMInterface.ps1 | 15 +-------------- .../Get-NetboxDCIMInterfaceConnection.ps1 | 15 +-------------- .../Interfaces/Remove-NetboxDCIMInterface.ps1 | 15 +-------------- .../Remove-NetboxDCIMInterfaceConnection.ps1 | 15 +-------------- .../DCIM/Interfaces/Set-NetboxDCIMInterface.ps1 | 15 +-------------- .../Set-NetboxDCIMInterfaceConnection.ps1 | 15 +-------------- Functions/DCIM/Sites/Get-NetboxDCIMSite.ps1 | 16 +--------------- Functions/Helpers/BuildNewURI.ps1 | 15 +-------------- Functions/Helpers/BuildURIComponents.ps1 | 15 +-------------- Functions/Helpers/CheckNetboxIsConnected.ps1 | 15 +-------------- Functions/Helpers/CreateEnum.ps1 | 15 +-------------- Functions/Helpers/Get-ModelDefinition.ps1 | 16 +--------------- Functions/Helpers/GetNetboxAPIErrorBody.ps1 | 15 +-------------- Functions/Helpers/InvokeNetboxRequest.ps1 | 15 +-------------- .../IPAM/Address/Get-NetboxIPAMAvailableIP.ps1 | 15 +-------------- Functions/IPAM/Address/New-NetboxIPAMAddress.ps1 | 15 +-------------- .../IPAM/Address/Remove-NetboxIPAMAddress.ps1 | 14 +------------- Functions/IPAM/Address/Set-NetboxIPAMAddress.ps1 | 15 +-------------- .../IPAM/Aggregate/Get-NetboxIPAMAggregate.ps1 | 15 +-------------- Functions/IPAM/Prefix/Get-NetboxIPAMPrefix.ps1 | 15 +-------------- Functions/IPAM/Prefix/New-NetboxIPAMPrefix.ps1 | 15 +-------------- Functions/IPAM/Prefix/Set-NetboxIPAMPrefix.ps1 | 15 +-------------- Functions/IPAM/VLAN/Get-NetboxIPAMVLAN.ps1 | 15 +-------------- .../Setup/Support/Get-NetboxAPIDefinition.ps1 | 16 +--------------- Functions/Tenancy/Get-NetboxTenant.ps1 | 15 +-------------- .../VirtualMachine/Get-NetboxVirtualMachine.ps1 | 15 +-------------- .../VirtualMachine/New-NetboxVirtualMachine.ps1 | 15 +-------------- .../Remove-NetboxVirtualMachine.ps1 | 15 +-------------- .../VirtualMachine/Set-NetboxVirtualMachine.ps1 | 15 +-------------- .../Add-NetboxVirtualMachineInterface.ps1 | 15 +-------------- .../Get-NetboxVirtualMachineInterface.ps1 | 15 +-------------- .../Set-NetboxVirtualMachineInterface.ps1 | 15 +-------------- .../Get-NetboxVirtualizationCluster.ps1 | 15 +-------------- .../Get-NetboxVirtualizationClusterGroup.ps1 | 15 +-------------- Tests/DCIM.Devices.Tests.ps1 | 14 +------------- Tests/DCIM.Interfaces.Tests.ps1 | 14 +------------- Tests/DCIM.Platforms.Tests.ps1 | 14 +------------- Tests/Helpers.Tests.ps1 | 14 +------------- Tests/IPAM.Tests.ps1 | 14 +------------- Tests/Setup.Tests.ps1 | 14 +------------- Tests/Virtualization.Tests.ps1 | 14 +------------- deploy.ps1 | 9 --------- 56 files changed, 55 insertions(+), 778 deletions(-) diff --git a/Functions/Circuits/Circuits/Get-NetboxCircuit.ps1 b/Functions/Circuits/Circuits/Get-NetboxCircuit.ps1 index 34b2ced..6664395 100644 --- a/Functions/Circuits/Circuits/Get-NetboxCircuit.ps1 +++ b/Functions/Circuits/Circuits/Get-NetboxCircuit.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:15 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxCircuit.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Get-NetboxCircuit { <# .SYNOPSIS diff --git a/Functions/Circuits/Circuits/New-NetboxCircuit.ps1 b/Functions/Circuits/Circuits/New-NetboxCircuit.ps1 index 650a006..8198749 100644 --- a/Functions/Circuits/Circuits/New-NetboxCircuit.ps1 +++ b/Functions/Circuits/Circuits/New-NetboxCircuit.ps1 @@ -1,18 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 - Created on: 2020-11-04 11:48 - Created by: Claussen - Organization: NEOnet - Filename: New-NetboxCircuit.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - - + function New-NetboxCircuit { [CmdletBinding(ConfirmImpact = 'Low', SupportsShouldProcess = $true)] diff --git a/Functions/Circuits/Providers/Get-NetboxCircuitProvider.ps1 b/Functions/Circuits/Providers/Get-NetboxCircuitProvider.ps1 index 8e392e0..8942e44 100644 --- a/Functions/Circuits/Providers/Get-NetboxCircuitProvider.ps1 +++ b/Functions/Circuits/Providers/Get-NetboxCircuitProvider.ps1 @@ -1,18 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 - Created on: 2020-11-04 12:06 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxCircuitProvider.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - - + function Get-NetboxCircuitProvider { [CmdletBinding(DefaultParameterSetName = 'Query')] param diff --git a/Functions/Circuits/Terminations/Get-NetboxCircuitTermination.ps1 b/Functions/Circuits/Terminations/Get-NetboxCircuitTermination.ps1 index 930c244..c8d46ba 100644 --- a/Functions/Circuits/Terminations/Get-NetboxCircuitTermination.ps1 +++ b/Functions/Circuits/Terminations/Get-NetboxCircuitTermination.ps1 @@ -1,18 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 - Created on: 2020-11-04 10:22 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxCircuitTermination.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - - + function Get-NetboxCircuitTermination { [CmdletBinding(DefaultParameterSetName = 'Query')] param diff --git a/Functions/Circuits/Types/Get-NetboxCircuitType.ps1 b/Functions/Circuits/Types/Get-NetboxCircuitType.ps1 index 16cd88e..4296cc7 100644 --- a/Functions/Circuits/Types/Get-NetboxCircuitType.ps1 +++ b/Functions/Circuits/Types/Get-NetboxCircuitType.ps1 @@ -1,18 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 - Created on: 2020-11-04 12:34 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxCircuitType.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - - + function Get-NetboxCircuitType { [CmdletBinding(DefaultParameterSetName = 'Query')] param diff --git a/Functions/DCIM/Devices/Get-NetboxDCIMDevice.ps1 b/Functions/DCIM/Devices/Get-NetboxDCIMDevice.ps1 index ff7237c..34184e3 100644 --- a/Functions/DCIM/Devices/Get-NetboxDCIMDevice.ps1 +++ b/Functions/DCIM/Devices/Get-NetboxDCIMDevice.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:06 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxDCIMDevice.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Get-NetboxDCIMDevice { [CmdletBinding()] #region Parameters diff --git a/Functions/DCIM/Devices/Get-NetboxDCIMDeviceRole.ps1 b/Functions/DCIM/Devices/Get-NetboxDCIMDeviceRole.ps1 index afcad80..a07f306 100644 --- a/Functions/DCIM/Devices/Get-NetboxDCIMDeviceRole.ps1 +++ b/Functions/DCIM/Devices/Get-NetboxDCIMDeviceRole.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:07 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxDCIMDeviceRole.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Get-NetboxDCIMDeviceRole { [CmdletBinding()] param diff --git a/Functions/DCIM/Devices/Get-NetboxDCIMDeviceType.ps1 b/Functions/DCIM/Devices/Get-NetboxDCIMDeviceType.ps1 index 5bd55b8..ee74128 100644 --- a/Functions/DCIM/Devices/Get-NetboxDCIMDeviceType.ps1 +++ b/Functions/DCIM/Devices/Get-NetboxDCIMDeviceType.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:07 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxDCIMDeviceType.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Get-NetboxDCIMDeviceType { [CmdletBinding()] #region Parameters diff --git a/Functions/DCIM/Devices/New-NetboxDCIMDevice.ps1 b/Functions/DCIM/Devices/New-NetboxDCIMDevice.ps1 index b99e237..ed9a51d 100644 --- a/Functions/DCIM/Devices/New-NetboxDCIMDevice.ps1 +++ b/Functions/DCIM/Devices/New-NetboxDCIMDevice.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:08 - Created by: Claussen - Organization: NEOnet - Filename: New-NetboxDCIMDevice.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function New-NetboxDCIMDevice { [CmdletBinding(ConfirmImpact = 'low', SupportsShouldProcess = $true)] diff --git a/Functions/DCIM/Devices/Remove-NetboxDCIMDevice.ps1 b/Functions/DCIM/Devices/Remove-NetboxDCIMDevice.ps1 index 747f959..a2af469 100644 --- a/Functions/DCIM/Devices/Remove-NetboxDCIMDevice.ps1 +++ b/Functions/DCIM/Devices/Remove-NetboxDCIMDevice.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:08 - Created by: Claussen - Organization: NEOnet - Filename: Remove-NetboxDCIMDevice.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Remove-NetboxDCIMDevice { <# .SYNOPSIS diff --git a/Functions/DCIM/Devices/Set-NetboxDCIMDevice.ps1 b/Functions/DCIM/Devices/Set-NetboxDCIMDevice.ps1 index 3bfac65..04e7cb2 100644 --- a/Functions/DCIM/Devices/Set-NetboxDCIMDevice.ps1 +++ b/Functions/DCIM/Devices/Set-NetboxDCIMDevice.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:08 - Created by: Claussen - Organization: NEOnet - Filename: Set-NetboxDCIMDevice.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Set-NetboxDCIMDevice { [CmdletBinding(SupportsShouldProcess = $true)] param diff --git a/Functions/DCIM/Get-NetboxDCIMPlatform.ps1 b/Functions/DCIM/Get-NetboxDCIMPlatform.ps1 index d2bd323..d6fe85f 100644 --- a/Functions/DCIM/Get-NetboxDCIMPlatform.ps1 +++ b/Functions/DCIM/Get-NetboxDCIMPlatform.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:13 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxDCIMPlatform.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Get-NetboxDCIMPlatform { [CmdletBinding()] [OutputType([pscustomobject])] diff --git a/Functions/DCIM/Interfaces/Add-NetboxDCIMInterface.ps1 b/Functions/DCIM/Interfaces/Add-NetboxDCIMInterface.ps1 index 75a5f29..d60129f 100644 --- a/Functions/DCIM/Interfaces/Add-NetboxDCIMInterface.ps1 +++ b/Functions/DCIM/Interfaces/Add-NetboxDCIMInterface.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:10 - Created by: Claussen - Organization: NEOnet - Filename: Add-NetboxDCIMInterface.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Add-NetboxDCIMInterface { [CmdletBinding()] [OutputType([pscustomobject])] diff --git a/Functions/DCIM/Interfaces/Add-NetboxDCIMInterfaceConnection.ps1 b/Functions/DCIM/Interfaces/Add-NetboxDCIMInterfaceConnection.ps1 index d848b0c..438654f 100644 --- a/Functions/DCIM/Interfaces/Add-NetboxDCIMInterfaceConnection.ps1 +++ b/Functions/DCIM/Interfaces/Add-NetboxDCIMInterfaceConnection.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:10 - Created by: Claussen - Organization: NEOnet - Filename: Add-NetboxDCIMInterfaceConnection.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Add-NetboxDCIMInterfaceConnection { <# .SYNOPSIS diff --git a/Functions/DCIM/Interfaces/Get-NetboxDCIMInterface.ps1 b/Functions/DCIM/Interfaces/Get-NetboxDCIMInterface.ps1 index f0c64f7..6fe7330 100644 --- a/Functions/DCIM/Interfaces/Get-NetboxDCIMInterface.ps1 +++ b/Functions/DCIM/Interfaces/Get-NetboxDCIMInterface.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:09 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxDCIMInterface.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Get-NetboxDCIMInterface { [CmdletBinding()] [OutputType([pscustomobject])] diff --git a/Functions/DCIM/Interfaces/Get-NetboxDCIMInterfaceConnection.ps1 b/Functions/DCIM/Interfaces/Get-NetboxDCIMInterfaceConnection.ps1 index 9c4ca22..9c90579 100644 --- a/Functions/DCIM/Interfaces/Get-NetboxDCIMInterfaceConnection.ps1 +++ b/Functions/DCIM/Interfaces/Get-NetboxDCIMInterfaceConnection.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:10 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxDCIMInterfaceConnection.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Get-NetboxDCIMInterfaceConnection { [CmdletBinding()] [OutputType([pscustomobject])] diff --git a/Functions/DCIM/Interfaces/Remove-NetboxDCIMInterface.ps1 b/Functions/DCIM/Interfaces/Remove-NetboxDCIMInterface.ps1 index 2e73c2b..8824b4c 100644 --- a/Functions/DCIM/Interfaces/Remove-NetboxDCIMInterface.ps1 +++ b/Functions/DCIM/Interfaces/Remove-NetboxDCIMInterface.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:11 - Created by: Claussen - Organization: NEOnet - Filename: Remove-NetboxDCIMInterface.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Remove-NetboxDCIMInterface { <# .SYNOPSIS diff --git a/Functions/DCIM/Interfaces/Remove-NetboxDCIMInterfaceConnection.ps1 b/Functions/DCIM/Interfaces/Remove-NetboxDCIMInterfaceConnection.ps1 index d7dc205..0d5eb5b 100644 --- a/Functions/DCIM/Interfaces/Remove-NetboxDCIMInterfaceConnection.ps1 +++ b/Functions/DCIM/Interfaces/Remove-NetboxDCIMInterfaceConnection.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:12 - Created by: Claussen - Organization: NEOnet - Filename: Remove-NetboxDCIMInterfaceConnection.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Remove-NetboxDCIMInterfaceConnection { [CmdletBinding(ConfirmImpact = 'High', SupportsShouldProcess = $true)] diff --git a/Functions/DCIM/Interfaces/Set-NetboxDCIMInterface.ps1 b/Functions/DCIM/Interfaces/Set-NetboxDCIMInterface.ps1 index d08ecd6..de7d5f2 100644 --- a/Functions/DCIM/Interfaces/Set-NetboxDCIMInterface.ps1 +++ b/Functions/DCIM/Interfaces/Set-NetboxDCIMInterface.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:11 - Created by: Claussen - Organization: NEOnet - Filename: Set-NetboxDCIMInterface.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Set-NetboxDCIMInterface { [CmdletBinding(ConfirmImpact = 'Medium', SupportsShouldProcess = $true)] diff --git a/Functions/DCIM/Interfaces/Set-NetboxDCIMInterfaceConnection.ps1 b/Functions/DCIM/Interfaces/Set-NetboxDCIMInterfaceConnection.ps1 index abe84aa..299d278 100644 --- a/Functions/DCIM/Interfaces/Set-NetboxDCIMInterfaceConnection.ps1 +++ b/Functions/DCIM/Interfaces/Set-NetboxDCIMInterfaceConnection.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:11 - Created by: Claussen - Organization: NEOnet - Filename: Set-NetboxDCIMInterfaceConnection.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Set-NetboxDCIMInterfaceConnection { <# .SYNOPSIS diff --git a/Functions/DCIM/Sites/Get-NetboxDCIMSite.ps1 b/Functions/DCIM/Sites/Get-NetboxDCIMSite.ps1 index 963e089..932644c 100644 --- a/Functions/DCIM/Sites/Get-NetboxDCIMSite.ps1 +++ b/Functions/DCIM/Sites/Get-NetboxDCIMSite.ps1 @@ -1,18 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 - Created on: 2020-10-02 15:52 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxDCIMSite.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - - + function Get-NetboxDCIMSite { [CmdletBinding(DefaultParameterSetName = 'Query')] [OutputType([pscustomobject])] diff --git a/Functions/Helpers/BuildNewURI.ps1 b/Functions/Helpers/BuildNewURI.ps1 index 700f339..b7a734b 100644 --- a/Functions/Helpers/BuildNewURI.ps1 +++ b/Functions/Helpers/BuildNewURI.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/26/2020 14:22 - Created by: Claussen - Organization: NEOnet - Filename: BuildNewURI.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function BuildNewURI { <# .SYNOPSIS diff --git a/Functions/Helpers/BuildURIComponents.ps1 b/Functions/Helpers/BuildURIComponents.ps1 index d9f60a8..54a13b5 100644 --- a/Functions/Helpers/BuildURIComponents.ps1 +++ b/Functions/Helpers/BuildURIComponents.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/26/2020 14:23 - Created by: Claussen - Organization: NEOnet - Filename: BuildURIComponents.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function BuildURIComponents { [CmdletBinding()] [OutputType([hashtable])] diff --git a/Functions/Helpers/CheckNetboxIsConnected.ps1 b/Functions/Helpers/CheckNetboxIsConnected.ps1 index aca5057..a3d8e4d 100644 --- a/Functions/Helpers/CheckNetboxIsConnected.ps1 +++ b/Functions/Helpers/CheckNetboxIsConnected.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/26/2020 14:22 - Created by: Claussen - Organization: NEOnet - Filename: CheckNetboxIsConnected.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function CheckNetboxIsConnected { [CmdletBinding()] param () diff --git a/Functions/Helpers/CreateEnum.ps1 b/Functions/Helpers/CreateEnum.ps1 index 89fe25a..1aa9595 100644 --- a/Functions/Helpers/CreateEnum.ps1 +++ b/Functions/Helpers/CreateEnum.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/26/2020 14:25 - Created by: Claussen - Organization: NEOnet - Filename: CreateEnum.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function CreateEnum { [CmdletBinding()] param diff --git a/Functions/Helpers/Get-ModelDefinition.ps1 b/Functions/Helpers/Get-ModelDefinition.ps1 index c8969c9..ac121b9 100644 --- a/Functions/Helpers/Get-ModelDefinition.ps1 +++ b/Functions/Helpers/Get-ModelDefinition.ps1 @@ -1,18 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 - Created on: 2020-11-04 14:23 - Created by: Claussen - Organization: NEOnet - Filename: Get-ModelDefinition.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - - + function Get-ModelDefinition { [CmdletBinding(DefaultParameterSetName = 'ByName')] param diff --git a/Functions/Helpers/GetNetboxAPIErrorBody.ps1 b/Functions/Helpers/GetNetboxAPIErrorBody.ps1 index 96bd3fe..bf70d02 100644 --- a/Functions/Helpers/GetNetboxAPIErrorBody.ps1 +++ b/Functions/Helpers/GetNetboxAPIErrorBody.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/26/2020 14:23 - Created by: Claussen - Organization: NEOnet - Filename: GetNetboxAPIErrorBody.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function GetNetboxAPIErrorBody { param ( diff --git a/Functions/Helpers/InvokeNetboxRequest.ps1 b/Functions/Helpers/InvokeNetboxRequest.ps1 index 9696518..d48a5b3 100644 --- a/Functions/Helpers/InvokeNetboxRequest.ps1 +++ b/Functions/Helpers/InvokeNetboxRequest.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/26/2020 14:24 - Created by: Claussen - Organization: NEOnet - Filename: InvokeNetboxRequest.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function InvokeNetboxRequest { [CmdletBinding()] param diff --git a/Functions/IPAM/Address/Get-NetboxIPAMAvailableIP.ps1 b/Functions/IPAM/Address/Get-NetboxIPAMAvailableIP.ps1 index e026cb8..d0699cb 100644 --- a/Functions/IPAM/Address/Get-NetboxIPAMAvailableIP.ps1 +++ b/Functions/IPAM/Address/Get-NetboxIPAMAvailableIP.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 11:50 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxIPAMAvailableIP.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Get-NetboxIPAMAvailableIP { <# .SYNOPSIS diff --git a/Functions/IPAM/Address/New-NetboxIPAMAddress.ps1 b/Functions/IPAM/Address/New-NetboxIPAMAddress.ps1 index 8650d9a..bffe7ad 100644 --- a/Functions/IPAM/Address/New-NetboxIPAMAddress.ps1 +++ b/Functions/IPAM/Address/New-NetboxIPAMAddress.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 11:51 - Created by: Claussen - Organization: NEOnet - Filename: New-NetboxIPAMAddress.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function New-NetboxIPAMAddress { <# .SYNOPSIS diff --git a/Functions/IPAM/Address/Remove-NetboxIPAMAddress.ps1 b/Functions/IPAM/Address/Remove-NetboxIPAMAddress.ps1 index 3173473..0ae5e42 100644 --- a/Functions/IPAM/Address/Remove-NetboxIPAMAddress.ps1 +++ b/Functions/IPAM/Address/Remove-NetboxIPAMAddress.ps1 @@ -1,16 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 11:52 - Created by: Claussen - Organization: NEOnet - Filename: Remove-NetboxIPAMAddress.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - + function Remove-NetboxIPAMAddress { <# .SYNOPSIS diff --git a/Functions/IPAM/Address/Set-NetboxIPAMAddress.ps1 b/Functions/IPAM/Address/Set-NetboxIPAMAddress.ps1 index ee1447f..7718a84 100644 --- a/Functions/IPAM/Address/Set-NetboxIPAMAddress.ps1 +++ b/Functions/IPAM/Address/Set-NetboxIPAMAddress.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 11:53 - Created by: Claussen - Organization: NEOnet - Filename: Set-NetboxIPAMAddress.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Set-NetboxIPAMAddress { [CmdletBinding(ConfirmImpact = 'Medium', SupportsShouldProcess = $true)] diff --git a/Functions/IPAM/Aggregate/Get-NetboxIPAMAggregate.ps1 b/Functions/IPAM/Aggregate/Get-NetboxIPAMAggregate.ps1 index 87e82da..0e99585 100644 --- a/Functions/IPAM/Aggregate/Get-NetboxIPAMAggregate.ps1 +++ b/Functions/IPAM/Aggregate/Get-NetboxIPAMAggregate.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 11:49 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxIPAMAggregate.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Get-NetboxIPAMAggregate { [CmdletBinding(DefaultParameterSetName = 'Query')] param diff --git a/Functions/IPAM/Prefix/Get-NetboxIPAMPrefix.ps1 b/Functions/IPAM/Prefix/Get-NetboxIPAMPrefix.ps1 index 11a5fd0..a680369 100644 --- a/Functions/IPAM/Prefix/Get-NetboxIPAMPrefix.ps1 +++ b/Functions/IPAM/Prefix/Get-NetboxIPAMPrefix.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 11:51 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxIPAMPrefix.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Get-NetboxIPAMPrefix { <# .SYNOPSIS diff --git a/Functions/IPAM/Prefix/New-NetboxIPAMPrefix.ps1 b/Functions/IPAM/Prefix/New-NetboxIPAMPrefix.ps1 index ea728b0..979cbdc 100644 --- a/Functions/IPAM/Prefix/New-NetboxIPAMPrefix.ps1 +++ b/Functions/IPAM/Prefix/New-NetboxIPAMPrefix.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 11:52 - Created by: Claussen - Organization: NEOnet - Filename: New-NetboxIPAMPrefix.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function New-NetboxIPAMPrefix { [CmdletBinding(ConfirmImpact = 'low', SupportsShouldProcess = $true)] diff --git a/Functions/IPAM/Prefix/Set-NetboxIPAMPrefix.ps1 b/Functions/IPAM/Prefix/Set-NetboxIPAMPrefix.ps1 index 8a6b384..025fdda 100644 --- a/Functions/IPAM/Prefix/Set-NetboxIPAMPrefix.ps1 +++ b/Functions/IPAM/Prefix/Set-NetboxIPAMPrefix.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2021 v5.8.186 - Created on: 2021-03-23 13:54 - Created by: Claussen - Organization: NEOnet - Filename: Set-NetboxIPAMPrefix.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Set-NetboxIPAMPrefix { [CmdletBinding(ConfirmImpact = 'Medium', SupportsShouldProcess = $true)] diff --git a/Functions/IPAM/VLAN/Get-NetboxIPAMVLAN.ps1 b/Functions/IPAM/VLAN/Get-NetboxIPAMVLAN.ps1 index fa78c1f..088b30f 100644 --- a/Functions/IPAM/VLAN/Get-NetboxIPAMVLAN.ps1 +++ b/Functions/IPAM/VLAN/Get-NetboxIPAMVLAN.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/16/2020 16:34 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxIPAMVLAN.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Get-NetboxIPAMVLAN { [CmdletBinding()] param diff --git a/Functions/Setup/Support/Get-NetboxAPIDefinition.ps1 b/Functions/Setup/Support/Get-NetboxAPIDefinition.ps1 index 4fcdf0c..1e42f7a 100644 --- a/Functions/Setup/Support/Get-NetboxAPIDefinition.ps1 +++ b/Functions/Setup/Support/Get-NetboxAPIDefinition.ps1 @@ -1,18 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.174 - Created on: 4/28/2020 11:57 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxAPIDefinition.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - - + function Get-NetboxAPIDefinition { [CmdletBinding()] param () diff --git a/Functions/Tenancy/Get-NetboxTenant.ps1 b/Functions/Tenancy/Get-NetboxTenant.ps1 index 1e0732a..af5250e 100644 --- a/Functions/Tenancy/Get-NetboxTenant.ps1 +++ b/Functions/Tenancy/Get-NetboxTenant.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 11:56 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxTenant.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Get-NetboxTenant { <# .SYNOPSIS diff --git a/Functions/Virtualization/VirtualMachine/Get-NetboxVirtualMachine.ps1 b/Functions/Virtualization/VirtualMachine/Get-NetboxVirtualMachine.ps1 index 34884e2..742b535 100644 --- a/Functions/Virtualization/VirtualMachine/Get-NetboxVirtualMachine.ps1 +++ b/Functions/Virtualization/VirtualMachine/Get-NetboxVirtualMachine.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 12:44 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxVirtualMachine.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Get-NetboxVirtualMachine { <# .SYNOPSIS diff --git a/Functions/Virtualization/VirtualMachine/New-NetboxVirtualMachine.ps1 b/Functions/Virtualization/VirtualMachine/New-NetboxVirtualMachine.ps1 index 46945de..98d2038 100644 --- a/Functions/Virtualization/VirtualMachine/New-NetboxVirtualMachine.ps1 +++ b/Functions/Virtualization/VirtualMachine/New-NetboxVirtualMachine.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 12:44 - Created by: Claussen - Organization: NEOnet - Filename: New-NetboxVirtualMachine.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function New-NetboxVirtualMachine { [CmdletBinding(ConfirmImpact = 'low', SupportsShouldProcess = $true)] diff --git a/Functions/Virtualization/VirtualMachine/Remove-NetboxVirtualMachine.ps1 b/Functions/Virtualization/VirtualMachine/Remove-NetboxVirtualMachine.ps1 index b2cb192..ebb733a 100644 --- a/Functions/Virtualization/VirtualMachine/Remove-NetboxVirtualMachine.ps1 +++ b/Functions/Virtualization/VirtualMachine/Remove-NetboxVirtualMachine.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 12:45 - Created by: Claussen - Organization: NEOnet - Filename: Remove-NetboxVirtualMachine.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Remove-NetboxVirtualMachine { <# .SYNOPSIS diff --git a/Functions/Virtualization/VirtualMachine/Set-NetboxVirtualMachine.ps1 b/Functions/Virtualization/VirtualMachine/Set-NetboxVirtualMachine.ps1 index bba99e7..8c8ae0e 100644 --- a/Functions/Virtualization/VirtualMachine/Set-NetboxVirtualMachine.ps1 +++ b/Functions/Virtualization/VirtualMachine/Set-NetboxVirtualMachine.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 12:45 - Created by: Claussen - Organization: NEOnet - Filename: Set-NetboxVirtualMachine.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Set-NetboxVirtualMachine { [CmdletBinding(ConfirmImpact = 'Medium', SupportsShouldProcess = $true)] diff --git a/Functions/Virtualization/VirtualMachineInterface/Add-NetboxVirtualMachineInterface.ps1 b/Functions/Virtualization/VirtualMachineInterface/Add-NetboxVirtualMachineInterface.ps1 index e197244..47a04a9 100644 --- a/Functions/Virtualization/VirtualMachineInterface/Add-NetboxVirtualMachineInterface.ps1 +++ b/Functions/Virtualization/VirtualMachineInterface/Add-NetboxVirtualMachineInterface.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 12:46 - Created by: Claussen - Organization: NEOnet - Filename: Add-NetboxVirtualMachineInterface.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Add-NetboxVirtualMachineInterface { [CmdletBinding()] param diff --git a/Functions/Virtualization/VirtualMachineInterface/Get-NetboxVirtualMachineInterface.ps1 b/Functions/Virtualization/VirtualMachineInterface/Get-NetboxVirtualMachineInterface.ps1 index 1b85127..d20d019 100644 --- a/Functions/Virtualization/VirtualMachineInterface/Get-NetboxVirtualMachineInterface.ps1 +++ b/Functions/Virtualization/VirtualMachineInterface/Get-NetboxVirtualMachineInterface.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 12:47 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxVirtualMachineInterface.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Get-NetboxVirtualMachineInterface { <# .SYNOPSIS diff --git a/Functions/Virtualization/VirtualMachineInterface/Set-NetboxVirtualMachineInterface.ps1 b/Functions/Virtualization/VirtualMachineInterface/Set-NetboxVirtualMachineInterface.ps1 index db16b46..03604ed 100644 --- a/Functions/Virtualization/VirtualMachineInterface/Set-NetboxVirtualMachineInterface.ps1 +++ b/Functions/Virtualization/VirtualMachineInterface/Set-NetboxVirtualMachineInterface.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 12:47 - Created by: Claussen - Organization: NEOnet - Filename: Set-NetboxVirtualMachineInterface.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Set-NetboxVirtualMachineInterface { [CmdletBinding(ConfirmImpact = 'Medium', SupportsShouldProcess = $true)] diff --git a/Functions/Virtualization/VirtualizationCluster/Get-NetboxVirtualizationCluster.ps1 b/Functions/Virtualization/VirtualizationCluster/Get-NetboxVirtualizationCluster.ps1 index 68e7f10..b151e62 100644 --- a/Functions/Virtualization/VirtualizationCluster/Get-NetboxVirtualizationCluster.ps1 +++ b/Functions/Virtualization/VirtualizationCluster/Get-NetboxVirtualizationCluster.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 14:10 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxVirtualizationCluster.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Get-NetboxVirtualizationCluster { <# .SYNOPSIS diff --git a/Functions/Virtualization/VirtualizationCluster/Get-NetboxVirtualizationClusterGroup.ps1 b/Functions/Virtualization/VirtualizationCluster/Get-NetboxVirtualizationClusterGroup.ps1 index 0269f5a..71813f7 100644 --- a/Functions/Virtualization/VirtualizationCluster/Get-NetboxVirtualizationClusterGroup.ps1 +++ b/Functions/Virtualization/VirtualizationCluster/Get-NetboxVirtualizationClusterGroup.ps1 @@ -1,17 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 14:11 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxVirtualizationClusterGroup.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - + function Get-NetboxVirtualizationClusterGroup { [CmdletBinding()] param diff --git a/Tests/DCIM.Devices.Tests.ps1 b/Tests/DCIM.Devices.Tests.ps1 index b3505c3..d8164bd 100644 --- a/Tests/DCIM.Devices.Tests.ps1 +++ b/Tests/DCIM.Devices.Tests.ps1 @@ -1,16 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.152 - Created on: 5/22/2018 4:48 PM - Created by: Ben Claussen - Organization: NEOnet - Filename: DCIM.Tests.ps1 - =========================================================================== - .DESCRIPTION - DCIM tests. -#> - + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] param ( diff --git a/Tests/DCIM.Interfaces.Tests.ps1 b/Tests/DCIM.Interfaces.Tests.ps1 index 2c268f9..e45572f 100644 --- a/Tests/DCIM.Interfaces.Tests.ps1 +++ b/Tests/DCIM.Interfaces.Tests.ps1 @@ -1,16 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.152 - Created on: 5/24/2018 10:50 AM - Created by: Ben Claussen - Organization: NEOnet - Filename: DCIM.Interfaces.Tests.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] param ( diff --git a/Tests/DCIM.Platforms.Tests.ps1 b/Tests/DCIM.Platforms.Tests.ps1 index 752957c..d335995 100644 --- a/Tests/DCIM.Platforms.Tests.ps1 +++ b/Tests/DCIM.Platforms.Tests.ps1 @@ -1,16 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.152 - Created on: 5/25/2018 1:03 PM - Created by: Ben Claussen - Organization: NEOnet - Filename: DCIM.Platforms.Tests.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] param ( diff --git a/Tests/Helpers.Tests.ps1 b/Tests/Helpers.Tests.ps1 index bfbbef9..3c34aaa 100644 --- a/Tests/Helpers.Tests.ps1 +++ b/Tests/Helpers.Tests.ps1 @@ -1,16 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.150 - Created on: 5/8/2018 11:36 AM - Created by: Ben Claussen - Organization: NEOnet - Filename: Helpers.Tests.ps1 - =========================================================================== - .DESCRIPTION - Helper functions Pester tests -#> - + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] param ( diff --git a/Tests/IPAM.Tests.ps1 b/Tests/IPAM.Tests.ps1 index 66a677a..92906f1 100644 --- a/Tests/IPAM.Tests.ps1 +++ b/Tests/IPAM.Tests.ps1 @@ -1,16 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.150 - Created on: 5/10/2018 3:41 PM - Created by: Ben Claussen - Organization: NEOnet - Filename: IPAM.Tests.ps1 - =========================================================================== - .DESCRIPTION - IPAM Pester tests -#> - + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] param ( diff --git a/Tests/Setup.Tests.ps1 b/Tests/Setup.Tests.ps1 index f9558d2..de06170 100644 --- a/Tests/Setup.Tests.ps1 +++ b/Tests/Setup.Tests.ps1 @@ -1,16 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.150 - Created on: 5/8/2018 10:33 AM - Created by: Ben Claussen - Organization: NEOnet - Filename: Setup.Tests.ps1 - =========================================================================== - .DESCRIPTION - Setup function Pester tests -#> - + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] param ( diff --git a/Tests/Virtualization.Tests.ps1 b/Tests/Virtualization.Tests.ps1 index f744a20..ed3175b 100644 --- a/Tests/Virtualization.Tests.ps1 +++ b/Tests/Virtualization.Tests.ps1 @@ -1,16 +1,4 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.150 - Created on: 5/8/2018 4:01 PM - Created by: Ben Claussen - Organization: NEOnet - Filename: Virtualization.Tests.ps1 - =========================================================================== - .DESCRIPTION - Virtualization Pester tests -#> - + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] param ( diff --git a/deploy.ps1 b/deploy.ps1 index 7cc3b44..b79da4f 100644 --- a/deploy.ps1 +++ b/deploy.ps1 @@ -30,15 +30,6 @@ Increment the version by 0.2.0. Given version 1.2.0, the resulting version will be 1.4.0 .\deploy.ps1 -VersionIncrease 0.2.0 - - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.174 - Created on: 4/9/2020 09:43 - Created by: Claussen - Organization: NEOnet - Filename: deploy.ps1 - =========================================================================== #> [CmdletBinding(DefaultParameterSetName = 'IncreaseVersion')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")] From ff0c0127cdfec045462273f5a87613aab1c7bb82 Mon Sep 17 00:00:00 2001 From: Claussen Date: Tue, 6 Dec 2022 13:35:47 -0500 Subject: [PATCH 41/68] Add explicit FunctionsToExport --- NetboxPS.psd1 | 41 +++++++++++++++++++++++++++++++++++++---- NetboxPS.psm1 | 16 +--------------- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/NetboxPS.psd1 b/NetboxPS.psd1 index d2ce728..b0db719 100644 --- a/NetboxPS.psd1 +++ b/NetboxPS.psd1 @@ -3,7 +3,7 @@ # # Generated by: Ben Claussen # -# Generated on: 2021-07-23 +# Generated on: 2022-12-06 # @{ @@ -12,7 +12,7 @@ RootModule = 'NetboxPS.psm1' # Version number of this module. -ModuleVersion = '1.5.0' +ModuleVersion = '1.5.5' # Supported PSEditions # CompatiblePSEditions = @() @@ -54,7 +54,7 @@ CLRVersion = '2.0.50727' # RequiredModules = @() # Assemblies that must be loaded prior to importing this module -#RequiredAssemblies = '' +# RequiredAssemblies = @() # Script files (.ps1) that are run in the caller's environment prior to importing this module. # ScriptsToProcess = @() @@ -69,7 +69,40 @@ CLRVersion = '2.0.50727' 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 = '*' +FunctionsToExport = 'Add-NetboxDCIMInterface', 'Add-NetboxDCIMInterfaceConnection', + '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-NetboxCredential', 'Get-NetboxDCIMDevice', + 'Get-NetboxDCIMDeviceRole', 'Get-NetboxDCIMDeviceType', + 'Get-NetboxDCIMInterface', 'Get-NetboxDCIMInterfaceConnection', + 'Get-NetboxDCIMPlatform', 'Get-NetboxDCIMSite', 'Get-NetboxHostname', + 'Get-NetboxHostPort', 'Get-NetboxHostScheme', + 'Get-NetboxInvokeParams', 'Get-NetboxIPAMAddress', + 'Get-NetboxIPAMAggregate', 'Get-NetboxIPAMAvailableIP', + 'Get-NetboxIPAMPrefix', 'Get-NetboxIPAMRole', 'Get-NetboxIPAMVLAN', + 'Get-NetboxTenant', 'Get-NetboxTimeout', 'Get-NetboxVersion', + 'Get-NetboxVirtualizationCluster', + 'Get-NetboxVirtualizationClusterGroup', 'Get-NetboxVirtualMachine', + 'Get-NetboxVirtualMachineInterface', 'InvokeNetboxRequest', + 'New-NetboxCircuit', 'New-NetboxDCIMDevice', 'New-NetboxDCIMSite', + 'New-NetboxIPAMAddress', 'New-NetboxIPAMPrefix', 'New-NetboxIPAMVLAN', + 'New-NetboxVirtualMachine', 'Remove-NetboxDCIMDevice', + 'Remove-NetboxDCIMInterface', + 'Remove-NetboxDCIMInterfaceConnection', 'Remove-NetboxDCIMSite', + 'Remove-NetboxIPAMAddress', 'Remove-NetboxVirtualMachine', + 'Set-NetboxCipherSSL', 'Set-NetboxCredential', 'Set-NetboxDCIMDevice', + 'Set-NetboxDCIMInterface', 'Set-NetboxDCIMInterfaceConnection', + 'Set-NetboxHostName', 'Set-NetboxHostPort', 'Set-NetboxHostScheme', + 'Set-NetboxInvokeParams', 'Set-NetboxIPAMAddress', + 'Set-NetboxIPAMPrefix', 'Set-NetboxTimeout', + 'Set-NetboxUnstrustedSSL', 'Set-NetboxVirtualMachine', + 'Set-NetboxVirtualMachineInterface', 'SetupNetboxConfigVariable', + '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 = '*' diff --git a/NetboxPS.psm1 b/NetboxPS.psm1 index 6d66fc6..3e83c2d 100644 --- a/NetboxPS.psm1 +++ b/NetboxPS.psm1 @@ -1,15 +1,4 @@ -<# - .NOTES - -------------------------------------------------------------------------------- - Code generated by: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Generated on: 3/26/2020 15:16 - Generated by: Claussen - Organization: NEOnet - -------------------------------------------------------------------------------- - .DESCRIPTION - Script generated by PowerShell Studio 2020 -#> - + # Build a list of common parameters so we can omit them to build URI parameters $script:CommonParameterNames = New-Object System.Collections.ArrayList [void]$script:CommonParameterNames.AddRange(@([System.Management.Automation.PSCmdlet]::CommonParameters)) @@ -17,6 +6,3 @@ $script:CommonParameterNames = New-Object System.Collections.ArrayList [void]$script:CommonParameterNames.Add('Raw') SetupNetboxConfigVariable - -Export-ModuleMember -Function * -#Export-ModuleMember -Function *-* \ No newline at end of file From e7a67328bf2f827c659d00b3e614a2907ec5fc5d Mon Sep 17 00:00:00 2001 From: Claussen Date: Tue, 6 Dec 2022 13:35:56 -0500 Subject: [PATCH 42/68] 1.5.5 --- NetboxPS/NetboxPS.psd1 | 41 +- NetboxPS/NetboxPS.psm1 | 826 ++++++++--------------------------------- 2 files changed, 197 insertions(+), 670 deletions(-) diff --git a/NetboxPS/NetboxPS.psd1 b/NetboxPS/NetboxPS.psd1 index 3cb6799..b0db719 100644 --- a/NetboxPS/NetboxPS.psd1 +++ b/NetboxPS/NetboxPS.psd1 @@ -3,7 +3,7 @@ # # Generated by: Ben Claussen # -# Generated on: 2021-07-23 +# Generated on: 2022-12-06 # @{ @@ -12,7 +12,7 @@ RootModule = 'NetboxPS.psm1' # Version number of this module. -ModuleVersion = '1.5.0' +ModuleVersion = '1.5.5' # Supported PSEditions # CompatiblePSEditions = @() @@ -54,7 +54,7 @@ CLRVersion = '2.0.50727' # RequiredModules = @() # Assemblies that must be loaded prior to importing this module -RequiredAssemblies = 'System.Web' +# RequiredAssemblies = @() # Script files (.ps1) that are run in the caller's environment prior to importing this module. # ScriptsToProcess = @() @@ -69,7 +69,40 @@ RequiredAssemblies = 'System.Web' 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 = '*' +FunctionsToExport = 'Add-NetboxDCIMInterface', 'Add-NetboxDCIMInterfaceConnection', + '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-NetboxCredential', 'Get-NetboxDCIMDevice', + 'Get-NetboxDCIMDeviceRole', 'Get-NetboxDCIMDeviceType', + 'Get-NetboxDCIMInterface', 'Get-NetboxDCIMInterfaceConnection', + 'Get-NetboxDCIMPlatform', 'Get-NetboxDCIMSite', 'Get-NetboxHostname', + 'Get-NetboxHostPort', 'Get-NetboxHostScheme', + 'Get-NetboxInvokeParams', 'Get-NetboxIPAMAddress', + 'Get-NetboxIPAMAggregate', 'Get-NetboxIPAMAvailableIP', + 'Get-NetboxIPAMPrefix', 'Get-NetboxIPAMRole', 'Get-NetboxIPAMVLAN', + 'Get-NetboxTenant', 'Get-NetboxTimeout', 'Get-NetboxVersion', + 'Get-NetboxVirtualizationCluster', + 'Get-NetboxVirtualizationClusterGroup', 'Get-NetboxVirtualMachine', + 'Get-NetboxVirtualMachineInterface', 'InvokeNetboxRequest', + 'New-NetboxCircuit', 'New-NetboxDCIMDevice', 'New-NetboxDCIMSite', + 'New-NetboxIPAMAddress', 'New-NetboxIPAMPrefix', 'New-NetboxIPAMVLAN', + 'New-NetboxVirtualMachine', 'Remove-NetboxDCIMDevice', + 'Remove-NetboxDCIMInterface', + 'Remove-NetboxDCIMInterfaceConnection', 'Remove-NetboxDCIMSite', + 'Remove-NetboxIPAMAddress', 'Remove-NetboxVirtualMachine', + 'Set-NetboxCipherSSL', 'Set-NetboxCredential', 'Set-NetboxDCIMDevice', + 'Set-NetboxDCIMInterface', 'Set-NetboxDCIMInterfaceConnection', + 'Set-NetboxHostName', 'Set-NetboxHostPort', 'Set-NetboxHostScheme', + 'Set-NetboxInvokeParams', 'Set-NetboxIPAMAddress', + 'Set-NetboxIPAMPrefix', 'Set-NetboxTimeout', + 'Set-NetboxUnstrustedSSL', 'Set-NetboxVirtualMachine', + 'Set-NetboxVirtualMachineInterface', 'SetupNetboxConfigVariable', + '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 = '*' diff --git a/NetboxPS/NetboxPS.psm1 b/NetboxPS/NetboxPS.psm1 index 7505c90..db99c47 100644 --- a/NetboxPS/NetboxPS.psm1 +++ b/NetboxPS/NetboxPS.psm1 @@ -2,19 +2,6 @@ #region File Add-NetboxDCIMInterface.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:10 - Created by: Claussen - Organization: NEOnet - Filename: Add-NetboxDCIMInterface.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Add-NetboxDCIMInterface { [CmdletBinding()] @@ -91,19 +78,6 @@ function Add-NetboxDCIMInterface { #region File Add-NetboxDCIMInterfaceConnection.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:10 - Created by: Claussen - Organization: NEOnet - Filename: Add-NetboxDCIMInterfaceConnection.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Add-NetboxDCIMInterfaceConnection { <# @@ -163,19 +137,6 @@ function Add-NetboxDCIMInterfaceConnection { #region File Add-NetboxVirtualMachineInterface.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 12:46 - Created by: Claussen - Organization: NEOnet - Filename: Add-NetboxVirtualMachineInterface.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Add-NetboxVirtualMachineInterface { [CmdletBinding()] @@ -213,19 +174,6 @@ function Add-NetboxVirtualMachineInterface { #region File BuildNewURI.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/26/2020 14:22 - Created by: Claussen - Organization: NEOnet - Filename: BuildNewURI.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function BuildNewURI { <# @@ -311,19 +259,6 @@ function BuildNewURI { #region File BuildURIComponents.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/26/2020 14:23 - Created by: Claussen - Organization: NEOnet - Filename: BuildURIComponents.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function BuildURIComponents { [CmdletBinding()] @@ -404,19 +339,6 @@ function BuildURIComponents { #region File CheckNetboxIsConnected.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/26/2020 14:22 - Created by: Claussen - Organization: NEOnet - Filename: CheckNetboxIsConnected.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function CheckNetboxIsConnected { [CmdletBinding()] @@ -535,6 +457,8 @@ function Connect-NetboxAPI { #for PowerShell (<=) 5 (Desktop), Enable TLS 1.1, 1.2 and Disable SSL chain trust if ("Desktop" -eq $PSVersionTable.PsEdition) { + #Add System.web (Need for ParseQueryString) + Add-Type -AssemblyName System.Web #Enable TLS 1.1 and 1.2 Set-NetboxCipherSSL if ($SkipCertificateCheck) { @@ -612,19 +536,6 @@ function Connect-NetboxAPI { #region File CreateEnum.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/26/2020 14:25 - Created by: Claussen - Organization: NEOnet - Filename: CreateEnum.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function CreateEnum { [CmdletBinding()] @@ -658,20 +569,6 @@ public enum $EnumName #region File Get-ModelDefinition.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 - Created on: 2020-11-04 14:23 - Created by: Claussen - Organization: NEOnet - Filename: Get-ModelDefinition.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - function Get-ModelDefinition { [CmdletBinding(DefaultParameterSetName = 'ByName')] @@ -727,20 +624,6 @@ function Get-ModelDefinition { #region File Get-NetboxAPIDefinition.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.174 - Created on: 4/28/2020 11:57 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxAPIDefinition.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - function Get-NetboxAPIDefinition { [CmdletBinding()] @@ -761,19 +644,6 @@ function Get-NetboxAPIDefinition { #region File GetNetboxAPIErrorBody.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/26/2020 14:23 - Created by: Claussen - Organization: NEOnet - Filename: GetNetboxAPIErrorBody.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function GetNetboxAPIErrorBody { param @@ -795,19 +665,6 @@ function GetNetboxAPIErrorBody { #region File Get-NetboxCircuit.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:15 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxCircuit.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Get-NetboxCircuit { <# @@ -933,20 +790,6 @@ function Get-NetboxCircuit { #region File Get-NetboxCircuitProvider.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 - Created on: 2020-11-04 12:06 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxCircuitProvider.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - function Get-NetboxCircuitProvider { [CmdletBinding(DefaultParameterSetName = 'Query')] @@ -1010,20 +853,6 @@ function Get-NetboxCircuitProvider { #region File Get-NetboxCircuitTermination.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 - Created on: 2020-11-04 10:22 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxCircuitTermination.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - function Get-NetboxCircuitTermination { [CmdletBinding(DefaultParameterSetName = 'Query')] @@ -1094,20 +923,6 @@ function Get-NetboxCircuitTermination { #region File Get-NetboxCircuitType.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 - Created on: 2020-11-04 12:34 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxCircuitType.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - function Get-NetboxCircuitType { [CmdletBinding(DefaultParameterSetName = 'Query')] @@ -1187,19 +1002,6 @@ function Get-NetboxCredential { #region File Get-NetboxDCIMDevice.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:06 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxDCIMDevice.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Get-NetboxDCIMDevice { [CmdletBinding()] @@ -1293,19 +1095,6 @@ function Get-NetboxDCIMDevice { #region File Get-NetboxDCIMDeviceRole.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:07 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxDCIMDeviceRole.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Get-NetboxDCIMDeviceRole { [CmdletBinding()] @@ -1360,19 +1149,6 @@ function Get-NetboxDCIMDeviceRole { #region File Get-NetboxDCIMDeviceType.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:07 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxDCIMDeviceType.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Get-NetboxDCIMDeviceType { [CmdletBinding()] @@ -1426,19 +1202,6 @@ function Get-NetboxDCIMDeviceType { #region File Get-NetboxDCIMInterface.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:09 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxDCIMInterface.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Get-NetboxDCIMInterface { [CmdletBinding()] @@ -1494,19 +1257,6 @@ function Get-NetboxDCIMInterface { #region File Get-NetboxDCIMInterfaceConnection.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:10 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxDCIMInterfaceConnection.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Get-NetboxDCIMInterfaceConnection { [CmdletBinding()] @@ -1545,19 +1295,6 @@ function Get-NetboxDCIMInterfaceConnection { #region File Get-NetboxDCIMPlatform.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:13 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxDCIMPlatform.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Get-NetboxDCIMPlatform { [CmdletBinding()] @@ -1613,23 +1350,9 @@ function Get-NetboxDCIMPlatform { #region File Get-NetboxDCIMSite.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 - Created on: 2020-10-02 15:52 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxDCIMSite.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - function Get-NetboxDCIMSite { - [CmdletBinding()] + [CmdletBinding(DefaultParameterSetName = 'Query')] [OutputType([pscustomobject])] param ( @@ -1723,7 +1446,6 @@ function Get-NetboxDCIMSite { } } - #endregion #region File Get-NetboxHostname.ps1 @@ -1810,7 +1532,7 @@ function Get-NetboxIPAMAddress { [object]$Family, [Parameter(ParameterSetName = 'Query')] - [uint32]$Parent, + [string]$Parent, [Parameter(ParameterSetName = 'Query')] [byte]$Mask_Length, @@ -1890,19 +1612,6 @@ function Get-NetboxIPAMAddress { #region File Get-NetboxIPAMAggregate.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 11:49 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxIPAMAggregate.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Get-NetboxIPAMAggregate { [CmdletBinding(DefaultParameterSetName = 'Query')] @@ -1974,19 +1683,6 @@ function Get-NetboxIPAMAggregate { #region File Get-NetboxIPAMAvailableIP.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 11:50 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxIPAMAvailableIP.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Get-NetboxIPAMAvailableIP { <# @@ -2052,19 +1748,6 @@ function Get-NetboxIPAMAvailableIP { #region File Get-NetboxIPAMPrefix.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 11:51 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxIPAMPrefix.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Get-NetboxIPAMPrefix { <# @@ -2363,19 +2046,6 @@ function Get-NetboxIPAMRole { #region File Get-NetboxIPAMVLAN.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/16/2020 16:34 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxIPAMVLAN.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Get-NetboxIPAMVLAN { [CmdletBinding()] @@ -2481,19 +2151,6 @@ function Get-NetboxIPAMVLAN { #region File Get-NetboxTenant.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 11:56 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxTenant.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Get-NetboxTenant { <# @@ -2645,19 +2302,6 @@ function Get-NetboxVersion { #region File Get-NetboxVirtualizationCluster.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 14:10 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxVirtualizationCluster.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Get-NetboxVirtualizationCluster { <# @@ -2752,19 +2396,6 @@ function Get-NetboxVirtualizationCluster { #region File Get-NetboxVirtualizationClusterGroup.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 14:11 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxVirtualizationClusterGroup.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Get-NetboxVirtualizationClusterGroup { [CmdletBinding()] @@ -2800,19 +2431,6 @@ function Get-NetboxVirtualizationClusterGroup { #region File Get-NetboxVirtualMachine.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 12:44 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxVirtualMachine.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Get-NetboxVirtualMachine { <# @@ -2962,19 +2580,6 @@ function Get-NetboxVirtualMachine { #region File Get-NetboxVirtualMachineInterface.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 12:47 - Created by: Claussen - Organization: NEOnet - Filename: Get-NetboxVirtualMachineInterface.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Get-NetboxVirtualMachineInterface { <# @@ -3063,19 +2668,6 @@ function Get-NetboxVirtualMachineInterface { #region File InvokeNetboxRequest.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/26/2020 14:24 - Created by: Claussen - Organization: NEOnet - Filename: InvokeNetboxRequest.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function InvokeNetboxRequest { [CmdletBinding()] @@ -3175,20 +2767,6 @@ function InvokeNetboxRequest { #region File New-NetboxCircuit.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 - Created on: 2020-11-04 11:48 - Created by: Claussen - Organization: NEOnet - Filename: New-NetboxCircuit.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - function New-NetboxCircuit { [CmdletBinding(ConfirmImpact = 'Low', @@ -3249,19 +2827,6 @@ function New-NetboxCircuit { #region File New-NetboxDCIMDevice.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:08 - Created by: Claussen - Organization: NEOnet - Filename: New-NetboxDCIMDevice.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function New-NetboxDCIMDevice { [CmdletBinding(ConfirmImpact = 'low', @@ -3345,22 +2910,100 @@ function New-NetboxDCIMDevice { #endregion -#region File New-NetboxIPAMAddress.ps1 +#region File New-NetboxDCIMSite.ps1 <# .NOTES =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 11:51 + Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 + Created on: 2020-10-02 15:52 Created by: Claussen Organization: NEOnet - Filename: New-NetboxIPAMAddress.ps1 + Filename: New-NetboxDCIMSite.ps1 =========================================================================== .DESCRIPTION A description of the file. #> + +function New-NetboxDCIMSite { + <# + .SYNOPSIS + Create a new Site to Netbox + + .DESCRIPTION + Create a new Site to Netbox + + .EXAMPLE + New-NetboxDCIMSite -name MySite + + Add new Site MySite on Netbox + + #> + + [CmdletBinding(ConfirmImpact = 'Low', + SupportsShouldProcess = $true)] + [OutputType([pscustomobject])] + param + ( + [Parameter(Mandatory = $true)] + [string]$Name, + + [string]$Slug, + + [string]$Facility, + + [uint32]$ASN, + + [decimal]$Latitude, + + [decimal]$Longitude, + + [string]$Contact_Name, + + [string]$Contact_Phone, + + [string]$Contact_Email, + + [int]$Tenant_Group, + + [int]$Tenant, + + [string]$Status, + + [uint32]$Region, + + [string]$Description, + + [string]$Comments, + + [switch]$Raw + ) + + process { + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites')) + $Method = 'POST' + + if (-not $PSBoundParameters.ContainsKey('slug')) { + $PSBoundParameters.Add('slug', $name) + } + + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters + + $URI = BuildNewURI -Segments $URIComponents.Segments + + if ($PSCmdlet.ShouldProcess($name, 'Create new Site')) { + InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw + } + } +} + +#endregion + +#region File New-NetboxIPAMAddress.ps1 + + function New-NetboxIPAMAddress { <# .SYNOPSIS @@ -3475,19 +3118,6 @@ function New-NetboxIPAMAddress { #region File New-NetboxIPAMPrefix.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 11:52 - Created by: Claussen - Organization: NEOnet - Filename: New-NetboxIPAMPrefix.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function New-NetboxIPAMPrefix { [CmdletBinding(ConfirmImpact = 'low', @@ -3630,19 +3260,6 @@ function New-NetboxIPAMVLAN { #region File New-NetboxVirtualMachine.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 12:44 - Created by: Claussen - Organization: NEOnet - Filename: New-NetboxVirtualMachine.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function New-NetboxVirtualMachine { [CmdletBinding(ConfirmImpact = 'low', @@ -3654,6 +3271,8 @@ function New-NetboxVirtualMachine { [string]$Name, [Parameter(Mandatory = $true)] + [uint16]$Site, + [uint16]$Cluster, [uint16]$Tenant, @@ -3688,6 +3307,10 @@ function New-NetboxVirtualMachine { #$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus + if ($PSBoundParameters.ContainsKey('Cluster') -and (-not $PSBoundParameters.ContainsKey('Site'))) { + throw "You must specify a site ID with a cluster ID" + } + $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines')) $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters @@ -3707,19 +3330,6 @@ function New-NetboxVirtualMachine { #region File Remove-NetboxDCIMDevice.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:08 - Created by: Claussen - Organization: NEOnet - Filename: Remove-NetboxDCIMDevice.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Remove-NetboxDCIMDevice { <# @@ -3780,19 +3390,6 @@ function Remove-NetboxDCIMDevice { #region File Remove-NetboxDCIMInterface.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:11 - Created by: Claussen - Organization: NEOnet - Filename: Remove-NetboxDCIMInterface.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Remove-NetboxDCIMInterface { <# @@ -3853,19 +3450,6 @@ function Remove-NetboxDCIMInterface { #region File Remove-NetboxDCIMInterfaceConnection.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:12 - Created by: Claussen - Organization: NEOnet - Filename: Remove-NetboxDCIMInterfaceConnection.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Remove-NetboxDCIMInterfaceConnection { [CmdletBinding(ConfirmImpact = 'High', @@ -3907,21 +3491,78 @@ function Remove-NetboxDCIMInterfaceConnection { #endregion -#region File Remove-NetboxIPAMAddress.ps1 +#region File Remove-NetboxDCIMSite.ps1 <# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 11:52 - Created by: Claussen - Organization: NEOnet - Filename: Remove-NetboxIPAMAddress.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. + .NOTES + =========================================================================== + Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 + Created on: 2020-10-02 15:52 + Created by: Claussen + Organization: NEOnet + Filename: New-NetboxDCIMSite.ps1 + =========================================================================== + .DESCRIPTION + A description of the file. #> + +function Remove-NetboxDCIMSite { + <# + .SYNOPSIS + Remove a Site + + .DESCRIPTION + Remove a DCIM Site from Netbox + + .EXAMPLE + Remove-NetboxDCIMSite -Id 1 + + Remove DCM Site with id 1 + + .EXAMPLE + Get-NetboxDCIMSite -name My Site | Remove-NetboxDCIMSite -confirm:$false + + Remove DCM Site with name My Site without confirmation + + #> + + [CmdletBinding(ConfirmImpact = 'High', + SupportsShouldProcess = $true)] + param + ( + [Parameter(Mandatory = $true, + ValueFromPipelineByPropertyName = $true)] + [uint]$Id + + ) + + begin { + + } + + process { + $CurrentSite = Get-NetboxDCIMSite -Id $Id -ErrorAction Stop + + if ($pscmdlet.ShouldProcess("$($CurrentSite.Name)/$($CurrentSite.Id)", "Remove Site")) { + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites', $CurrentSite.Id)) + + $URI = BuildNewURI -Segments $Segments + + InvokeNetboxRequest -URI $URI -Method DELETE + } + } + + end { + + } +} + +#endregion + +#region File Remove-NetboxIPAMAddress.ps1 + + function Remove-NetboxIPAMAddress { <# .SYNOPSIS @@ -3973,19 +3614,6 @@ function Remove-NetboxIPAMAddress { #region File Remove-NetboxVirtualMachine.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 12:45 - Created by: Claussen - Organization: NEOnet - Filename: Remove-NetboxVirtualMachine.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Remove-NetboxVirtualMachine { <# @@ -4096,19 +3724,6 @@ function Set-NetboxCredential { #region File Set-NetboxDCIMDevice.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:08 - Created by: Claussen - Organization: NEOnet - Filename: Set-NetboxDCIMDevice.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Set-NetboxDCIMDevice { [CmdletBinding(SupportsShouldProcess = $true)] @@ -4196,19 +3811,6 @@ function Set-NetboxDCIMDevice { #region File Set-NetboxDCIMInterface.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:11 - Created by: Claussen - Organization: NEOnet - Filename: Set-NetboxDCIMInterface.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Set-NetboxDCIMInterface { [CmdletBinding(ConfirmImpact = 'Medium', @@ -4302,19 +3904,6 @@ function Set-NetboxDCIMInterface { #region File Set-NetboxDCIMInterfaceConnection.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/23/2020 12:11 - Created by: Claussen - Organization: NEOnet - Filename: Set-NetboxDCIMInterfaceConnection.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Set-NetboxDCIMInterfaceConnection { <# @@ -4483,19 +4072,6 @@ function Set-NetboxInvokeParams { #region File Set-NetboxIPAMAddress.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 11:53 - Created by: Claussen - Organization: NEOnet - Filename: Set-NetboxIPAMAddress.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Set-NetboxIPAMAddress { [CmdletBinding(ConfirmImpact = 'Medium', @@ -4584,19 +4160,6 @@ function Set-NetboxIPAMAddress { #region File Set-NetboxIPAMPrefix.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2021 v5.8.186 - Created on: 2021-03-23 13:54 - Created by: Claussen - Organization: NEOnet - Filename: Set-NetboxIPAMPrefix.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Set-NetboxIPAMPrefix { [CmdletBinding(ConfirmImpact = 'Medium', @@ -4727,19 +4290,6 @@ Function Set-NetboxUntrustedSSL { #region File Set-NetboxVirtualMachine.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 12:45 - Created by: Claussen - Organization: NEOnet - Filename: Set-NetboxVirtualMachine.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Set-NetboxVirtualMachine { [CmdletBinding(ConfirmImpact = 'Medium', @@ -4806,19 +4356,6 @@ function Set-NetboxVirtualMachine { #region File Set-NetboxVirtualMachineInterface.ps1 -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/19/2020 12:47 - Created by: Claussen - Organization: NEOnet - Filename: Set-NetboxVirtualMachineInterface.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - function Set-NetboxVirtualMachineInterface { [CmdletBinding(ConfirmImpact = 'Medium', @@ -4899,35 +4436,6 @@ function SetupNetboxConfigVariable { #endregion -#region File ThrowNetboxRESTError.ps1 - -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/26/2020 14:25 - Created by: Claussen - Organization: NEOnet - Filename: ThrowNetboxRESTError.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - -function ThrowNetboxRESTError { - $uriSegments = [System.Collections.ArrayList]::new(@('fake', 'url')) - - $URIParameters = @{ - } - - $uri = BuildNewURI -Segments $uriSegments -Parameters $URIParameters - - InvokeNetboxRequest -URI $uri -Raw -} - -#endregion - #region File VerifyAPIConnectivity.ps1 function VerifyAPIConnectivity { @@ -4943,17 +4451,6 @@ function VerifyAPIConnectivity { #endregion -<# - .NOTES - -------------------------------------------------------------------------------- - Code generated by: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Generated on: 3/26/2020 15:16 - Generated by: Claussen - Organization: NEOnet - -------------------------------------------------------------------------------- - .DESCRIPTION - Script generated by PowerShell Studio 2020 -#> # Build a list of common parameters so we can omit them to build URI parameters $script:CommonParameterNames = New-Object System.Collections.ArrayList @@ -4962,6 +4459,3 @@ $script:CommonParameterNames = New-Object System.Collections.ArrayList [void]$script:CommonParameterNames.Add('Raw') SetupNetboxConfigVariable - -Export-ModuleMember -Function * -#Export-ModuleMember -Function *-* From 6b8caf0bd796c0443567f9dc3d4dbde45d1e55c8 Mon Sep 17 00:00:00 2001 From: Claussen Date: Tue, 6 Dec 2022 13:36:44 -0500 Subject: [PATCH 43/68] 1.5.6 - production function exports --- NetboxPS.psd1 | 22 +++++++++------------- NetboxPS/NetboxPS.psd1 | 22 +++++++++------------- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/NetboxPS.psd1 b/NetboxPS.psd1 index b0db719..3842193 100644 --- a/NetboxPS.psd1 +++ b/NetboxPS.psd1 @@ -12,7 +12,7 @@ RootModule = 'NetboxPS.psm1' # Version number of this module. -ModuleVersion = '1.5.5' +ModuleVersion = '1.5.6' # Supported PSEditions # CompatiblePSEditions = @() @@ -70,13 +70,10 @@ 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-NetboxDCIMInterface', 'Add-NetboxDCIMInterfaceConnection', - 'Add-NetboxVirtualMachineInterface', 'BuildNewURI', - 'BuildURIComponents', 'CheckNetboxIsConnected', - 'Clear-NetboxCredential', 'Connect-NetboxAPI', 'CreateEnum', - 'Get-ModelDefinition', 'Get-NetboxAPIDefinition', - 'GetNetboxAPIErrorBody', 'Get-NetboxCircuit', - 'Get-NetboxCircuitProvider', 'Get-NetboxCircuitTermination', - 'Get-NetboxCircuitType', 'GetNetboxConfigVariable', + 'Add-NetboxVirtualMachineInterface', 'Clear-NetboxCredential', + 'Connect-NetboxAPI', 'Get-ModelDefinition', 'Get-NetboxAPIDefinition', + 'Get-NetboxCircuit', 'Get-NetboxCircuitProvider', + 'Get-NetboxCircuitTermination', 'Get-NetboxCircuitType', 'Get-NetboxCredential', 'Get-NetboxDCIMDevice', 'Get-NetboxDCIMDeviceRole', 'Get-NetboxDCIMDeviceType', 'Get-NetboxDCIMInterface', 'Get-NetboxDCIMInterfaceConnection', @@ -88,9 +85,9 @@ FunctionsToExport = 'Add-NetboxDCIMInterface', 'Add-NetboxDCIMInterfaceConnectio 'Get-NetboxTenant', 'Get-NetboxTimeout', 'Get-NetboxVersion', 'Get-NetboxVirtualizationCluster', 'Get-NetboxVirtualizationClusterGroup', 'Get-NetboxVirtualMachine', - 'Get-NetboxVirtualMachineInterface', 'InvokeNetboxRequest', - 'New-NetboxCircuit', 'New-NetboxDCIMDevice', 'New-NetboxDCIMSite', - 'New-NetboxIPAMAddress', 'New-NetboxIPAMPrefix', 'New-NetboxIPAMVLAN', + 'Get-NetboxVirtualMachineInterface', 'New-NetboxCircuit', + 'New-NetboxDCIMDevice', 'New-NetboxDCIMSite', 'New-NetboxIPAMAddress', + 'New-NetboxIPAMPrefix', 'New-NetboxIPAMVLAN', 'New-NetboxVirtualMachine', 'Remove-NetboxDCIMDevice', 'Remove-NetboxDCIMInterface', 'Remove-NetboxDCIMInterfaceConnection', 'Remove-NetboxDCIMSite', @@ -101,8 +98,7 @@ FunctionsToExport = 'Add-NetboxDCIMInterface', 'Add-NetboxDCIMInterfaceConnectio 'Set-NetboxInvokeParams', 'Set-NetboxIPAMAddress', 'Set-NetboxIPAMPrefix', 'Set-NetboxTimeout', 'Set-NetboxUnstrustedSSL', 'Set-NetboxVirtualMachine', - 'Set-NetboxVirtualMachineInterface', 'SetupNetboxConfigVariable', - 'VerifyAPIConnectivity' + 'Set-NetboxVirtualMachineInterface' # 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 = '*' diff --git a/NetboxPS/NetboxPS.psd1 b/NetboxPS/NetboxPS.psd1 index b0db719..3842193 100644 --- a/NetboxPS/NetboxPS.psd1 +++ b/NetboxPS/NetboxPS.psd1 @@ -12,7 +12,7 @@ RootModule = 'NetboxPS.psm1' # Version number of this module. -ModuleVersion = '1.5.5' +ModuleVersion = '1.5.6' # Supported PSEditions # CompatiblePSEditions = @() @@ -70,13 +70,10 @@ 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-NetboxDCIMInterface', 'Add-NetboxDCIMInterfaceConnection', - 'Add-NetboxVirtualMachineInterface', 'BuildNewURI', - 'BuildURIComponents', 'CheckNetboxIsConnected', - 'Clear-NetboxCredential', 'Connect-NetboxAPI', 'CreateEnum', - 'Get-ModelDefinition', 'Get-NetboxAPIDefinition', - 'GetNetboxAPIErrorBody', 'Get-NetboxCircuit', - 'Get-NetboxCircuitProvider', 'Get-NetboxCircuitTermination', - 'Get-NetboxCircuitType', 'GetNetboxConfigVariable', + 'Add-NetboxVirtualMachineInterface', 'Clear-NetboxCredential', + 'Connect-NetboxAPI', 'Get-ModelDefinition', 'Get-NetboxAPIDefinition', + 'Get-NetboxCircuit', 'Get-NetboxCircuitProvider', + 'Get-NetboxCircuitTermination', 'Get-NetboxCircuitType', 'Get-NetboxCredential', 'Get-NetboxDCIMDevice', 'Get-NetboxDCIMDeviceRole', 'Get-NetboxDCIMDeviceType', 'Get-NetboxDCIMInterface', 'Get-NetboxDCIMInterfaceConnection', @@ -88,9 +85,9 @@ FunctionsToExport = 'Add-NetboxDCIMInterface', 'Add-NetboxDCIMInterfaceConnectio 'Get-NetboxTenant', 'Get-NetboxTimeout', 'Get-NetboxVersion', 'Get-NetboxVirtualizationCluster', 'Get-NetboxVirtualizationClusterGroup', 'Get-NetboxVirtualMachine', - 'Get-NetboxVirtualMachineInterface', 'InvokeNetboxRequest', - 'New-NetboxCircuit', 'New-NetboxDCIMDevice', 'New-NetboxDCIMSite', - 'New-NetboxIPAMAddress', 'New-NetboxIPAMPrefix', 'New-NetboxIPAMVLAN', + 'Get-NetboxVirtualMachineInterface', 'New-NetboxCircuit', + 'New-NetboxDCIMDevice', 'New-NetboxDCIMSite', 'New-NetboxIPAMAddress', + 'New-NetboxIPAMPrefix', 'New-NetboxIPAMVLAN', 'New-NetboxVirtualMachine', 'Remove-NetboxDCIMDevice', 'Remove-NetboxDCIMInterface', 'Remove-NetboxDCIMInterfaceConnection', 'Remove-NetboxDCIMSite', @@ -101,8 +98,7 @@ FunctionsToExport = 'Add-NetboxDCIMInterface', 'Add-NetboxDCIMInterfaceConnectio 'Set-NetboxInvokeParams', 'Set-NetboxIPAMAddress', 'Set-NetboxIPAMPrefix', 'Set-NetboxTimeout', 'Set-NetboxUnstrustedSSL', 'Set-NetboxVirtualMachine', - 'Set-NetboxVirtualMachineInterface', 'SetupNetboxConfigVariable', - 'VerifyAPIConnectivity' + 'Set-NetboxVirtualMachineInterface' # 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 = '*' From ea75e796eff78a2638644e4b9648a2908fa9717f Mon Sep 17 00:00:00 2001 From: weidi Date: Tue, 6 Dec 2022 19:48:46 +0100 Subject: [PATCH 44/68] Add Basic usage in README.md (#30) --- README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/README.md b/README.md index 5763fc1..a29827e 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,46 @@ This module is a wrapper for the [Netbox](https://github.com/netbox-community/ne 2. Import module 3. Connect to an API endpoint by using `Connect-NetboxAPI -Hostname netbox.example.com` +## Basic Commands + +```powershell +#Just adding a new IP +New-NetboxIPAMAddress -Address 10.0.0.1/24 -Dns_name this.is.thedns.fqdn -Custom_Fields @{CustomFieldID="CustomFieldContent"} -Tenant 1 -Description "Description" + +#Creating a new VM, add an interface and assign Interface IP +function New-NBVirtualMachine +{ + [CmdletBinding()] + [Alias()] + [OutputType([int])] + Param + ( + [string]$Name, + [string]$Cluster, + [string]$IP, + [string]$tenant, + [string]$VMNICName + ) + + Begin + { + $NBCluster = Get-NetboxVirtualizationCluster -name $Cluster + $NBTenant = Get-NetboxTenant -Name $tenant + } + Process + { + $vm = New-NetboxVirtualMachine -Name $Name -Cluster $NBCluster.id -Tenant $NBtenant.id + $interface = Add-NetboxVirtualMachineInterface -Name $VMNICName -Virtual_Machine $vm.id + + + $NBip = New-NetboxIPAMAddress -Address $IP -Tenant $NBtenant.id + Set-NetboxIPAMAddress -Assigned_Object_Type virtualization.vminterface -Assigned_Object_Id $interface.id -id $NBip.id + Set-NetboxVirtualMachine -Primary_IP4 $NBip.id -Id $vm.id + } +} + +``` + # Notes I started this project years ago with Powershell Studio using the built in deployment methods, learning Git, and learning PS best practices. So please forgive any "obvious" mistakes 😅 Over time I have had to adjust my methods for deployment... change the design of functions, and refactor code as I learn new and better things. From d7c008871df0845d571ae453c4ff15454479a0e2 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Tue, 6 Dec 2022 19:49:35 +0100 Subject: [PATCH 45/68] Tests (integration) DCIM (#34) * Tests: Add Initial support of Integration (using Pester v5) * Site: Add Tests for New/Get/Remove (DCIM) Site --- Tests/.gitignore | 1 + Tests/common.ps1 | 19 ++++++ Tests/credential.example.ps1 | 13 ++++ Tests/integration/DCIM.Site.Tests.ps1 | 85 +++++++++++++++++++++++++++ 4 files changed, 118 insertions(+) create mode 100644 Tests/.gitignore create mode 100644 Tests/common.ps1 create mode 100644 Tests/credential.example.ps1 create mode 100644 Tests/integration/DCIM.Site.Tests.ps1 diff --git a/Tests/.gitignore b/Tests/.gitignore new file mode 100644 index 0000000..c6e1f89 --- /dev/null +++ b/Tests/.gitignore @@ -0,0 +1 @@ +credential.ps1 \ No newline at end of file diff --git a/Tests/common.ps1 b/Tests/common.ps1 new file mode 100644 index 0000000..116dc24 --- /dev/null +++ b/Tests/common.ps1 @@ -0,0 +1,19 @@ +# +# Copyright 2021, Alexis La Goutte +# +# SPDX-License-Identifier: Apache-2.0 +# +[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] +Param() + +$script:pester_site1 = "pester_site1" + +$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 diff --git a/Tests/credential.example.ps1 b/Tests/credential.example.ps1 new file mode 100644 index 0000000..81c7adc --- /dev/null +++ b/Tests/credential.example.ps1 @@ -0,0 +1,13 @@ +# +# Copyright 2021, Alexis La Goutte +# +# SPDX-License-Identifier: Apache-2.0 +# + +# Copy this file to credential.ps1 (on Tests folder) and change connection settings.. + +$script:hostname = "10.44.23.213" +$script:token = "aaaaaaaaaaaaaaaaaa" + +#Uncomment if you want to personnalize some setting +#script:pester_site1 = "pester_site1" diff --git a/Tests/integration/DCIM.Site.Tests.ps1 b/Tests/integration/DCIM.Site.Tests.ps1 new file mode 100644 index 0000000..295188d --- /dev/null +++ b/Tests/integration/DCIM.Site.Tests.ps1 @@ -0,0 +1,85 @@ +# +# Copyright 2021, Alexis La Goutte +# +# SPDX-License-Identifier: Apache-2.0 +# +. ../common.ps1 + +BeforeAll { + Connect-NetboxAPI @invokeParams +} + +Describe "Get (DCIM) Site" { + + BeforeAll { + New-NetboxDCIMSite -name $pester_site1 + } + + It "Get Site Does not throw an error" { + { + Get-NetboxDCIMSite + } | Should -Not -Throw + } + + It "Get ALL Site" { + $site = Get-NetboxDCIMSite + $site.count | Should -Not -Be $NULL + } + + It "Get Site ($pester_site1)" { + $site = Get-NetboxDCIMSite | Where-Object { $_.name -eq $pester_site1 } + $site.id | Should -Not -BeNullOrEmpty + $site.name | Should -Be $pester_site1 + $site.status.value | Should -Be "active" + } + + It "Search Site by name ($pester_site1)" { + $site = Get-NetboxDCIMSite -name $pester_site1 + @($site).count | Should -Be 1 + $site.id | Should -Not -BeNullOrEmpty + $site.name | Should -Be $pester_site1 + } + + AfterAll { + Get-NetboxDCIMSite -name $pester_site1 | Remove-NetboxDCIMSite -confirm:$false + } +} + +Describe "New (DCIM) Site" { + + It "New Site with no option" { + New-NetboxDCIMSite -name $pester_site1 + $site = Get-NetboxDCIMSite -name $pester_site1 + $site.id | Should -Not -BeNullOrEmpty + $site.name | Should -Be $pester_site1 + $site.slug | Should -Be $pester_site1 + } + + It "New Site with different slug" { + New-NetboxDCIMSite -name $pester_site1 -slug pester_slug + $site = Get-NetboxDCIMSite -name $pester_site1 + $site.id | Should -Not -BeNullOrEmpty + $site.name | Should -Be $pester_site1 + $site.slug | Should -Be "pester_slug" + } + + AfterEach { + Get-NetboxDCIMSite -name $pester_site1 | Remove-NetboxDCIMSite -confirm:$false + } +} + +Describe "Remove Site" { + + BeforeEach { + New-NetboxDCIMSite -name $pester_site1 + } + + It "Remove Site" { + $site = Get-NetboxDCIMSite -name $pester_site1 + Remove-NetboxDCIMSite -id $site.id -confirm:$false + $site = Get-NetboxDCIMSite -name $pester_site1 + $site | Should -BeNullOrEmpty + @($site).count | Should -Be 0 + } + +} \ No newline at end of file From d85f67546937e80e01d02a08091760ae2bddff81 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Wed, 15 Feb 2023 15:39:36 -0500 Subject: [PATCH 46/68] 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 47/68] 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 48/68] 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 49/68] 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 50/68] 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 51/68] 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 52/68] 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 53/68] 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 54/68] 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 55/68] 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 56/68] 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 57/68] 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 58/68] 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 59/68] 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 } From 1f3626f319178bc1c1fa61d78079fe5968908bc5 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Thu, 16 Feb 2023 09:49:13 -0500 Subject: [PATCH 60/68] Update test version to 1.6.0 --- NetboxPS.psd1 | 26 +- NetboxPS/NetboxPS.psd1 | 26 +- NetboxPS/NetboxPS.psm1 | 703 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 737 insertions(+), 18 deletions(-) diff --git a/NetboxPS.psd1 b/NetboxPS.psd1 index 3842193..4cc1e3c 100644 --- a/NetboxPS.psd1 +++ b/NetboxPS.psd1 @@ -3,7 +3,7 @@ # # Generated by: Ben Claussen # -# Generated on: 2022-12-06 +# Generated on: 2023-02-16 # @{ @@ -12,7 +12,7 @@ RootModule = 'NetboxPS.psm1' # Version number of this module. -ModuleVersion = '1.5.6' +ModuleVersion = '1.6.0' # Supported PSEditions # CompatiblePSEditions = @() @@ -70,10 +70,15 @@ 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-NetboxDCIMInterface', 'Add-NetboxDCIMInterfaceConnection', - '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-NetboxDCIMDevice', 'Get-NetboxDCIMDeviceRole', 'Get-NetboxDCIMDeviceType', 'Get-NetboxDCIMInterface', 'Get-NetboxDCIMInterfaceConnection', @@ -85,9 +90,11 @@ FunctionsToExport = 'Add-NetboxDCIMInterface', 'Add-NetboxDCIMInterfaceConnectio 'Get-NetboxTenant', 'Get-NetboxTimeout', 'Get-NetboxVersion', 'Get-NetboxVirtualizationCluster', 'Get-NetboxVirtualizationClusterGroup', 'Get-NetboxVirtualMachine', - 'Get-NetboxVirtualMachineInterface', 'New-NetboxCircuit', + 'Get-NetboxVirtualMachineInterface', + 'Initialize-NetboxContentTypeEnum', 'InvokeNetboxRequest', + 'New-NetboxCircuit', 'New-NetboxContact', 'New-NetboxContactRole', 'New-NetboxDCIMDevice', 'New-NetboxDCIMSite', 'New-NetboxIPAMAddress', - 'New-NetboxIPAMPrefix', 'New-NetboxIPAMVLAN', + 'New-NetboxIPAMPrefix', 'New-NetboxIPAMVLAN', 'New-NetboxTenant', 'New-NetboxVirtualMachine', 'Remove-NetboxDCIMDevice', 'Remove-NetboxDCIMInterface', 'Remove-NetboxDCIMInterfaceConnection', 'Remove-NetboxDCIMSite', @@ -98,7 +105,8 @@ FunctionsToExport = 'Add-NetboxDCIMInterface', 'Add-NetboxDCIMInterfaceConnectio 'Set-NetboxInvokeParams', 'Set-NetboxIPAMAddress', 'Set-NetboxIPAMPrefix', 'Set-NetboxTimeout', 'Set-NetboxUnstrustedSSL', 'Set-NetboxVirtualMachine', - 'Set-NetboxVirtualMachineInterface' + 'Set-NetboxVirtualMachineInterface', 'SetupNetboxConfigVariable', + '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 = '*' diff --git a/NetboxPS/NetboxPS.psd1 b/NetboxPS/NetboxPS.psd1 index 3842193..4cc1e3c 100644 --- a/NetboxPS/NetboxPS.psd1 +++ b/NetboxPS/NetboxPS.psd1 @@ -3,7 +3,7 @@ # # Generated by: Ben Claussen # -# Generated on: 2022-12-06 +# Generated on: 2023-02-16 # @{ @@ -12,7 +12,7 @@ RootModule = 'NetboxPS.psm1' # Version number of this module. -ModuleVersion = '1.5.6' +ModuleVersion = '1.6.0' # Supported PSEditions # CompatiblePSEditions = @() @@ -70,10 +70,15 @@ 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-NetboxDCIMInterface', 'Add-NetboxDCIMInterfaceConnection', - '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-NetboxDCIMDevice', 'Get-NetboxDCIMDeviceRole', 'Get-NetboxDCIMDeviceType', 'Get-NetboxDCIMInterface', 'Get-NetboxDCIMInterfaceConnection', @@ -85,9 +90,11 @@ FunctionsToExport = 'Add-NetboxDCIMInterface', 'Add-NetboxDCIMInterfaceConnectio 'Get-NetboxTenant', 'Get-NetboxTimeout', 'Get-NetboxVersion', 'Get-NetboxVirtualizationCluster', 'Get-NetboxVirtualizationClusterGroup', 'Get-NetboxVirtualMachine', - 'Get-NetboxVirtualMachineInterface', 'New-NetboxCircuit', + 'Get-NetboxVirtualMachineInterface', + 'Initialize-NetboxContentTypeEnum', 'InvokeNetboxRequest', + 'New-NetboxCircuit', 'New-NetboxContact', 'New-NetboxContactRole', 'New-NetboxDCIMDevice', 'New-NetboxDCIMSite', 'New-NetboxIPAMAddress', - 'New-NetboxIPAMPrefix', 'New-NetboxIPAMVLAN', + 'New-NetboxIPAMPrefix', 'New-NetboxIPAMVLAN', 'New-NetboxTenant', 'New-NetboxVirtualMachine', 'Remove-NetboxDCIMDevice', 'Remove-NetboxDCIMInterface', 'Remove-NetboxDCIMInterfaceConnection', 'Remove-NetboxDCIMSite', @@ -98,7 +105,8 @@ FunctionsToExport = 'Add-NetboxDCIMInterface', 'Add-NetboxDCIMInterfaceConnectio 'Set-NetboxInvokeParams', 'Set-NetboxIPAMAddress', 'Set-NetboxIPAMPrefix', 'Set-NetboxTimeout', 'Set-NetboxUnstrustedSSL', 'Set-NetboxVirtualMachine', - 'Set-NetboxVirtualMachineInterface' + 'Set-NetboxVirtualMachineInterface', 'SetupNetboxConfigVariable', + '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 = '*' diff --git a/NetboxPS/NetboxPS.psm1 b/NetboxPS/NetboxPS.psm1 index db99c47..e83b308 100644 --- a/NetboxPS/NetboxPS.psm1 +++ b/NetboxPS/NetboxPS.psm1 @@ -984,6 +984,433 @@ function GetNetboxConfigVariable { #endregion +#region File Get-NetboxContact.ps1 + + +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 + } + } +} + +#endregion + +#region File Get-NetboxContactAssignment.ps1 + + +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 + } + } +} + +#endregion + +#region File Get-NetboxContactRole.ps1 + + +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 + } + } +} + +#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')] + [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 + } + } +} + +#endregion + #region File Get-NetboxCredential.ps1 function Get-NetboxCredential { @@ -2664,6 +3091,26 @@ function Get-NetboxVirtualMachineInterface { } } +#endregion + +#region File Initialize-NetboxContentTypeEnum.ps1 + +<# + .NOTES + =========================================================================== + Created with: SAPIEN Technologies, Inc., PowerShell Studio 2022 v5.8.212 + Created on: 2023-02-15 16:47 + Created by: Claussen + Organization: NEOnet + Filename: Initialize-NetboxContentTypeEnum.ps1 + =========================================================================== + .DESCRIPTION + A description of the file. +#> + + + + #endregion #region File InvokeNetboxRequest.ps1 @@ -2823,6 +3270,186 @@ function New-NetboxCircuit { } } +#endregion + +#region File New-NetboxContact.ps1 + + +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 + } + } +} + + + + + +#endregion + +#region File New-NetboxContactRole.ps1 + + +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 + } + } +} + + + + + #endregion #region File New-NetboxDCIMDevice.ps1 @@ -3256,6 +3883,82 @@ function New-NetboxIPAMVLAN { } } +#endregion + +#region File New-NetboxTenant.ps1 + + +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 + } + } +} + + + + + #endregion #region File New-NetboxVirtualMachine.ps1 From aa444871a4071c1885309e1104becfa786344f59 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Thu, 16 Feb 2023 15:05:28 -0500 Subject: [PATCH 61/68] Update psproj --- NetboxPS.psproj | 1 - 1 file changed, 1 deletion(-) diff --git a/NetboxPS.psproj b/NetboxPS.psproj index bad6789..a29241c 100644 --- a/NetboxPS.psproj +++ b/NetboxPS.psproj @@ -127,7 +127,6 @@ 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 From 6654f798b056ca806182fcb43a6e48c64910f584 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Fri, 24 Feb 2023 10:23:10 -0500 Subject: [PATCH 62/68] Add Set-NetboxContact --- .../Tenancy/Contacts/Set-NetboxContact.ps1 | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 Functions/Tenancy/Contacts/Set-NetboxContact.ps1 diff --git a/Functions/Tenancy/Contacts/Set-NetboxContact.ps1 b/Functions/Tenancy/Contacts/Set-NetboxContact.ps1 new file mode 100644 index 0000000..9b695c2 --- /dev/null +++ b/Functions/Tenancy/Contacts/Set-NetboxContact.ps1 @@ -0,0 +1,120 @@ + +function Set-NetboxContact { +<# + .SYNOPSIS + Update a contact in Netbox + + .DESCRIPTION + Updates a contact object in Netbox which can be linked to other objects + + .PARAMETER Id + A description of the Id parameter. + + .PARAMETER Name + The contacts full name, e.g "Leroy Jenkins" + + .PARAMETER Email + Email address of the contact + + .PARAMETER Group + Database ID of assigned group + + .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 Force + A description of the Force parameter. + + .PARAMETER Raw + A description of the Raw parameter. + + .EXAMPLE + PS C:\> Set-NetboxContact -Id 10 -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)] + [uint32[]]$Id, + + [ValidateLength(1, 100)] + [string]$Name, + + [ValidateLength(0, 254)] + [string]$Email, + + [uint32]$Group, + + [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]$Force, + + [switch]$Raw + ) + + begin { + $Method = 'PATCH' + } + + process { + foreach ($ContactId in $Id) { + $Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contacts', $ContactId)) + + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force' + + $URI = BuildNewURI -Segments $URIComponents.Segments + + $CurrentContact = Get-NetboxContact -Id $ContactId + + if ($Force -or $PSCmdlet.ShouldProcess($CurrentContact.Name, 'Update contact')) { + InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw + } + } + } +} + + + + From c1a0675b022d22f040fb1915deef903f9166d5cd Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Fri, 24 Feb 2023 10:23:27 -0500 Subject: [PATCH 63/68] Update psproj --- NetboxPS.psproj | 1 + 1 file changed, 1 insertion(+) diff --git a/NetboxPS.psproj b/NetboxPS.psproj index a29241c..91c2618 100644 --- a/NetboxPS.psproj +++ b/NetboxPS.psproj @@ -128,6 +128,7 @@ Functions\Tenancy\ContactAssignment\Get-NetboxContactAssignment.ps1 Functions\Setup\Support\Get-NetboxContentType.ps1 Functions\Tenancy\ContactAssignment\New-NetboxContactAssignment.ps1 + Functions\Tenancy\Contacts\Set-NetboxContact.ps1 R:\Netbox\NetboxPS\Test-Module.ps1 \ No newline at end of file From 1fed2d27e60404afb975ae4b5fea41f44c7a622d Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Fri, 24 Feb 2023 10:28:16 -0500 Subject: [PATCH 64/68] Fix #28 - Set DefaultParameterSetName = Query --- Functions/IPAM/VLAN/Get-NetboxIPAMVLAN.ps1 | 62 ++++++++++------------ 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/Functions/IPAM/VLAN/Get-NetboxIPAMVLAN.ps1 b/Functions/IPAM/VLAN/Get-NetboxIPAMVLAN.ps1 index 088b30f..3cd801e 100644 --- a/Functions/IPAM/VLAN/Get-NetboxIPAMVLAN.ps1 +++ b/Functions/IPAM/VLAN/Get-NetboxIPAMVLAN.ps1 @@ -1,95 +1,91 @@  function Get-NetboxIPAMVLAN { - [CmdletBinding()] + [CmdletBinding(DefaultParameterSetName = 'Query')] param ( [Parameter(ParameterSetName = 'Query', Position = 0)] [ValidateRange(1, 4096)] [uint16]$VID, - + [Parameter(ParameterSetName = 'ByID')] [uint32[]]$Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Query, - + [Parameter(ParameterSetName = 'Query')] [string]$Name, - + [Parameter(ParameterSetName = 'Query')] [string]$Tenant, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Tenant_Id, - + [Parameter(ParameterSetName = 'Query')] [string]$TenantGroup, - + [Parameter(ParameterSetName = 'Query')] [uint32]$TenantGroup_Id, - + [Parameter(ParameterSetName = 'Query')] [object]$Status, - + [Parameter(ParameterSetName = 'Query')] [string]$Region, - + [Parameter(ParameterSetName = 'Query')] [string]$Site, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Site_Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Group, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Group_Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Role, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Role_Id, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Limit, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Offset, - + [switch]$Raw ) - - # if ($null -ne $Status) { - # $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus - # } - + switch ($PSCmdlet.ParameterSetName) { 'ById' { foreach ($VLAN_ID in $Id) { $Segments = [System.Collections.ArrayList]::new(@('ipam', 'vlans', $VLAN_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(@('ipam', 'vlans')) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $uri -Raw:$Raw - + break } } From 44dc6c86a219704c876393d61f7a469a07e31d1b Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Fri, 24 Feb 2023 11:46:06 -0500 Subject: [PATCH 65/68] Update deploy.ps1 --- deploy.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/deploy.ps1 b/deploy.ps1 index c272fd9..720065f 100644 --- a/deploy.ps1 +++ b/deploy.ps1 @@ -155,7 +155,12 @@ Copy-Item -Path $ConcatenatedFilePath -Destination $PSM1OutputPath -Force Write-Host "Deployment complete" -ForegroundColor Green if ($ResetCurrentEnvironment) { Write-Warning "Running commands to reset current environment" + if (Get-Module 'NetboxPS') { + Remove-Module NetboxPS -Force + } + Write-Host " Reimporting module" Import-Module $PSM1OutputPath, $PSD1OutputPath -Force -ErrorAction Stop + Write-Host "Reset complete" -ForegroundColor Green } From 010fb0410b1bdef3e492283c34bc8138b81959d2 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Fri, 24 Feb 2023 11:51:04 -0500 Subject: [PATCH 66/68] Increment version to 1.7.0 --- NetboxPS.psd1 | 38 +++-- NetboxPS/NetboxPS.psd1 | 38 +++-- NetboxPS/NetboxPS.psm1 | 325 ++++++++++++++++++++++++++++++++++------- 3 files changed, 305 insertions(+), 96 deletions(-) diff --git a/NetboxPS.psd1 b/NetboxPS.psd1 index 4cc1e3c..0a0240d 100644 --- a/NetboxPS.psd1 +++ b/NetboxPS.psd1 @@ -3,7 +3,7 @@ # # Generated by: Ben Claussen # -# Generated on: 2023-02-16 +# Generated on: 2023-02-24 # @{ @@ -12,7 +12,7 @@ RootModule = 'NetboxPS.psm1' # Version number of this module. -ModuleVersion = '1.6.0' +ModuleVersion = '1.7.0' # Supported PSEditions # CompatiblePSEditions = @() @@ -70,13 +70,10 @@ 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-NetboxDCIMInterface', 'Add-NetboxDCIMInterfaceConnection', - 'Add-NetboxVirtualMachineInterface', 'BuildNewURI', - 'BuildURIComponents', 'CheckNetboxIsConnected', - 'Clear-NetboxCredential', 'Connect-NetboxAPI', 'CreateEnum', - 'Get-ModelDefinition', 'Get-NetboxAPIDefinition', - 'GetNetboxAPIErrorBody', 'Get-NetboxCircuit', - 'Get-NetboxCircuitProvider', 'Get-NetboxCircuitTermination', - 'Get-NetboxCircuitType', 'GetNetboxConfigVariable', + 'Add-NetboxVirtualMachineInterface', 'Clear-NetboxCredential', + 'Connect-NetboxAPI', 'Get-ModelDefinition', 'Get-NetboxAPIDefinition', + 'Get-NetboxCircuit', 'Get-NetboxCircuitProvider', + 'Get-NetboxCircuitTermination', 'Get-NetboxCircuitType', 'Get-NetboxContact', 'Get-NetboxContactAssignment', 'Get-NetboxContactRole', 'Get-NetboxContentType', 'Get-NetboxCredential', 'Get-NetboxDCIMDevice', @@ -90,23 +87,22 @@ FunctionsToExport = 'Add-NetboxDCIMInterface', 'Add-NetboxDCIMInterfaceConnectio 'Get-NetboxTenant', 'Get-NetboxTimeout', 'Get-NetboxVersion', 'Get-NetboxVirtualizationCluster', 'Get-NetboxVirtualizationClusterGroup', 'Get-NetboxVirtualMachine', - 'Get-NetboxVirtualMachineInterface', - 'Initialize-NetboxContentTypeEnum', 'InvokeNetboxRequest', - 'New-NetboxCircuit', 'New-NetboxContact', 'New-NetboxContactRole', - 'New-NetboxDCIMDevice', 'New-NetboxDCIMSite', 'New-NetboxIPAMAddress', - 'New-NetboxIPAMPrefix', 'New-NetboxIPAMVLAN', 'New-NetboxTenant', - 'New-NetboxVirtualMachine', 'Remove-NetboxDCIMDevice', - 'Remove-NetboxDCIMInterface', + 'Get-NetboxVirtualMachineInterface', 'New-NetboxCircuit', + 'New-NetboxContact', 'New-NetboxContactAssignment', + 'New-NetboxContactRole', 'New-NetboxDCIMDevice', 'New-NetboxDCIMSite', + 'New-NetboxIPAMAddress', 'New-NetboxIPAMPrefix', 'New-NetboxIPAMVLAN', + 'New-NetboxTenant', 'New-NetboxVirtualMachine', + 'Remove-NetboxDCIMDevice', 'Remove-NetboxDCIMInterface', 'Remove-NetboxDCIMInterfaceConnection', 'Remove-NetboxDCIMSite', 'Remove-NetboxIPAMAddress', 'Remove-NetboxVirtualMachine', - 'Set-NetboxCipherSSL', 'Set-NetboxCredential', 'Set-NetboxDCIMDevice', - 'Set-NetboxDCIMInterface', 'Set-NetboxDCIMInterfaceConnection', - 'Set-NetboxHostName', 'Set-NetboxHostPort', 'Set-NetboxHostScheme', + 'Set-NetboxCipherSSL', 'Set-NetboxContact', 'Set-NetboxCredential', + 'Set-NetboxDCIMDevice', 'Set-NetboxDCIMInterface', + 'Set-NetboxDCIMInterfaceConnection', 'Set-NetboxHostName', + 'Set-NetboxHostPort', 'Set-NetboxHostScheme', 'Set-NetboxInvokeParams', 'Set-NetboxIPAMAddress', 'Set-NetboxIPAMPrefix', 'Set-NetboxTimeout', 'Set-NetboxUnstrustedSSL', 'Set-NetboxVirtualMachine', - 'Set-NetboxVirtualMachineInterface', 'SetupNetboxConfigVariable', - 'VerifyAPIConnectivity' + 'Set-NetboxVirtualMachineInterface' # 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 = '*' diff --git a/NetboxPS/NetboxPS.psd1 b/NetboxPS/NetboxPS.psd1 index 4cc1e3c..0a0240d 100644 --- a/NetboxPS/NetboxPS.psd1 +++ b/NetboxPS/NetboxPS.psd1 @@ -3,7 +3,7 @@ # # Generated by: Ben Claussen # -# Generated on: 2023-02-16 +# Generated on: 2023-02-24 # @{ @@ -12,7 +12,7 @@ RootModule = 'NetboxPS.psm1' # Version number of this module. -ModuleVersion = '1.6.0' +ModuleVersion = '1.7.0' # Supported PSEditions # CompatiblePSEditions = @() @@ -70,13 +70,10 @@ 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-NetboxDCIMInterface', 'Add-NetboxDCIMInterfaceConnection', - 'Add-NetboxVirtualMachineInterface', 'BuildNewURI', - 'BuildURIComponents', 'CheckNetboxIsConnected', - 'Clear-NetboxCredential', 'Connect-NetboxAPI', 'CreateEnum', - 'Get-ModelDefinition', 'Get-NetboxAPIDefinition', - 'GetNetboxAPIErrorBody', 'Get-NetboxCircuit', - 'Get-NetboxCircuitProvider', 'Get-NetboxCircuitTermination', - 'Get-NetboxCircuitType', 'GetNetboxConfigVariable', + 'Add-NetboxVirtualMachineInterface', 'Clear-NetboxCredential', + 'Connect-NetboxAPI', 'Get-ModelDefinition', 'Get-NetboxAPIDefinition', + 'Get-NetboxCircuit', 'Get-NetboxCircuitProvider', + 'Get-NetboxCircuitTermination', 'Get-NetboxCircuitType', 'Get-NetboxContact', 'Get-NetboxContactAssignment', 'Get-NetboxContactRole', 'Get-NetboxContentType', 'Get-NetboxCredential', 'Get-NetboxDCIMDevice', @@ -90,23 +87,22 @@ FunctionsToExport = 'Add-NetboxDCIMInterface', 'Add-NetboxDCIMInterfaceConnectio 'Get-NetboxTenant', 'Get-NetboxTimeout', 'Get-NetboxVersion', 'Get-NetboxVirtualizationCluster', 'Get-NetboxVirtualizationClusterGroup', 'Get-NetboxVirtualMachine', - 'Get-NetboxVirtualMachineInterface', - 'Initialize-NetboxContentTypeEnum', 'InvokeNetboxRequest', - 'New-NetboxCircuit', 'New-NetboxContact', 'New-NetboxContactRole', - 'New-NetboxDCIMDevice', 'New-NetboxDCIMSite', 'New-NetboxIPAMAddress', - 'New-NetboxIPAMPrefix', 'New-NetboxIPAMVLAN', 'New-NetboxTenant', - 'New-NetboxVirtualMachine', 'Remove-NetboxDCIMDevice', - 'Remove-NetboxDCIMInterface', + 'Get-NetboxVirtualMachineInterface', 'New-NetboxCircuit', + 'New-NetboxContact', 'New-NetboxContactAssignment', + 'New-NetboxContactRole', 'New-NetboxDCIMDevice', 'New-NetboxDCIMSite', + 'New-NetboxIPAMAddress', 'New-NetboxIPAMPrefix', 'New-NetboxIPAMVLAN', + 'New-NetboxTenant', 'New-NetboxVirtualMachine', + 'Remove-NetboxDCIMDevice', 'Remove-NetboxDCIMInterface', 'Remove-NetboxDCIMInterfaceConnection', 'Remove-NetboxDCIMSite', 'Remove-NetboxIPAMAddress', 'Remove-NetboxVirtualMachine', - 'Set-NetboxCipherSSL', 'Set-NetboxCredential', 'Set-NetboxDCIMDevice', - 'Set-NetboxDCIMInterface', 'Set-NetboxDCIMInterfaceConnection', - 'Set-NetboxHostName', 'Set-NetboxHostPort', 'Set-NetboxHostScheme', + 'Set-NetboxCipherSSL', 'Set-NetboxContact', 'Set-NetboxCredential', + 'Set-NetboxDCIMDevice', 'Set-NetboxDCIMInterface', + 'Set-NetboxDCIMInterfaceConnection', 'Set-NetboxHostName', + 'Set-NetboxHostPort', 'Set-NetboxHostScheme', 'Set-NetboxInvokeParams', 'Set-NetboxIPAMAddress', 'Set-NetboxIPAMPrefix', 'Set-NetboxTimeout', 'Set-NetboxUnstrustedSSL', 'Set-NetboxVirtualMachine', - 'Set-NetboxVirtualMachineInterface', 'SetupNetboxConfigVariable', - 'VerifyAPIConnectivity' + 'Set-NetboxVirtualMachineInterface' # 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 = '*' diff --git a/NetboxPS/NetboxPS.psm1 b/NetboxPS/NetboxPS.psm1 index e83b308..15c2b54 100644 --- a/NetboxPS/NetboxPS.psm1 +++ b/NetboxPS/NetboxPS.psm1 @@ -516,7 +516,9 @@ function Connect-NetboxAPI { } 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!" @@ -2475,96 +2477,92 @@ function Get-NetboxIPAMRole { function Get-NetboxIPAMVLAN { - [CmdletBinding()] + [CmdletBinding(DefaultParameterSetName = 'Query')] param ( [Parameter(ParameterSetName = 'Query', Position = 0)] [ValidateRange(1, 4096)] [uint16]$VID, - + [Parameter(ParameterSetName = 'ByID')] [uint32[]]$Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Query, - + [Parameter(ParameterSetName = 'Query')] [string]$Name, - + [Parameter(ParameterSetName = 'Query')] [string]$Tenant, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Tenant_Id, - + [Parameter(ParameterSetName = 'Query')] [string]$TenantGroup, - + [Parameter(ParameterSetName = 'Query')] [uint32]$TenantGroup_Id, - + [Parameter(ParameterSetName = 'Query')] [object]$Status, - + [Parameter(ParameterSetName = 'Query')] [string]$Region, - + [Parameter(ParameterSetName = 'Query')] [string]$Site, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Site_Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Group, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Group_Id, - + [Parameter(ParameterSetName = 'Query')] [string]$Role, - + [Parameter(ParameterSetName = 'Query')] [uint32]$Role_Id, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Limit, - + [Parameter(ParameterSetName = 'Query')] [uint16]$Offset, - + [switch]$Raw ) - - # if ($null -ne $Status) { - # $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus - # } - + switch ($PSCmdlet.ParameterSetName) { 'ById' { foreach ($VLAN_ID in $Id) { $Segments = [System.Collections.ArrayList]::new(@('ipam', 'vlans', $VLAN_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(@('ipam', 'vlans')) - + $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters - + $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters - + InvokeNetboxRequest -URI $uri -Raw:$Raw - + break } } @@ -3091,26 +3089,6 @@ function Get-NetboxVirtualMachineInterface { } } -#endregion - -#region File Initialize-NetboxContentTypeEnum.ps1 - -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2022 v5.8.212 - Created on: 2023-02-15 16:47 - Created by: Claussen - Organization: NEOnet - Filename: Initialize-NetboxContentTypeEnum.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - - - #endregion #region File InvokeNetboxRequest.ps1 @@ -3374,6 +3352,119 @@ function New-NetboxContact { +#endregion + +#region File New-NetboxContactAssignment.ps1 + + +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 + } + } +} + + + + + #endregion #region File New-NetboxContactRole.ps1 @@ -4386,6 +4477,131 @@ Function Set-NetboxCipherSSL { } +#endregion + +#region File Set-NetboxContact.ps1 + + +function Set-NetboxContact { +<# + .SYNOPSIS + Update a contact in Netbox + + .DESCRIPTION + Updates a contact object in Netbox which can be linked to other objects + + .PARAMETER Id + A description of the Id parameter. + + .PARAMETER Name + The contacts full name, e.g "Leroy Jenkins" + + .PARAMETER Email + Email address of the contact + + .PARAMETER Group + Database ID of assigned group + + .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 Force + A description of the Force parameter. + + .PARAMETER Raw + A description of the Raw parameter. + + .EXAMPLE + PS C:\> Set-NetboxContact -Id 10 -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)] + [uint32[]]$Id, + + [ValidateLength(1, 100)] + [string]$Name, + + [ValidateLength(0, 254)] + [string]$Email, + + [uint32]$Group, + + [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]$Force, + + [switch]$Raw + ) + + begin { + $Method = 'PATCH' + } + + process { + foreach ($ContactId in $Id) { + $Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contacts', $ContactId)) + + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force' + + $URI = BuildNewURI -Segments $URIComponents.Segments + + $CurrentContact = Get-NetboxContact -Id $ContactId + + if ($Force -or $PSCmdlet.ShouldProcess($CurrentContact.Name, 'Update contact')) { + InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw + } + } + } +} + + + + + #endregion #region File Set-NetboxCredential.ps1 @@ -5131,6 +5347,7 @@ function SetupNetboxConfigVariable { 'Choices' = @{ } 'APIDefinition' = $null + 'ContentTypes' = $null } } From 3e0d817267e659eefcd0d98282033b271951ba25 Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Fri, 24 Feb 2023 12:12:54 -0500 Subject: [PATCH 67/68] Fix order of operations for Connect-NetboxAPI - Move successful connection boolean declaration before call to Get-NetboxContentType --- Functions/Setup/Connect-NetboxAPI.ps1 | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/Functions/Setup/Connect-NetboxAPI.ps1 b/Functions/Setup/Connect-NetboxAPI.ps1 index 974cfc6..cd36c32 100644 --- a/Functions/Setup/Connect-NetboxAPI.ps1 +++ b/Functions/Setup/Connect-NetboxAPI.ps1 @@ -145,19 +145,10 @@ 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!" - - #Write-Verbose "Caching static choices" - #$script:NetboxConfig.Choices.Circuits = Get-NetboxCircuitsChoices - #$script:NetboxConfig.Choices.DCIM = Get-NetboxDCIMChoices # Not completed yet - #$script:NetboxConfig.Choices.Extras = Get-NetboxExtrasChoices - #$script:NetboxConfig.Choices.IPAM = Get-NetboxIPAMChoices - ##$script:NetboxConfig.Choices.Secrets = Get-NetboxSecretsChoices # Not completed yet - ##$script:NetboxConfig.Choices.Tenancy = Get-NetboxTenancyChoices - #$script:NetboxConfig.Choices.Virtualization = Get-NetboxVirtualizationChoices + + $script:NetboxConfig.ContentTypes = Get-NetboxContentType -Limit 500 Write-Verbose "Connection process completed" } \ No newline at end of file From 7925db838fe33760cca29cbb6b65e7f5d587511f Mon Sep 17 00:00:00 2001 From: Ben Claussen Date: Fri, 24 Feb 2023 12:13:24 -0500 Subject: [PATCH 68/68] Increment version to 1.7.1 --- NetboxPS.psd1 | 2 +- NetboxPS/NetboxPS.psd1 | 2 +- NetboxPS/NetboxPS.psm1 | 13 ++----------- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/NetboxPS.psd1 b/NetboxPS.psd1 index 0a0240d..401b317 100644 --- a/NetboxPS.psd1 +++ b/NetboxPS.psd1 @@ -12,7 +12,7 @@ RootModule = 'NetboxPS.psm1' # Version number of this module. -ModuleVersion = '1.7.0' +ModuleVersion = '1.7.1' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/NetboxPS/NetboxPS.psd1 b/NetboxPS/NetboxPS.psd1 index 0a0240d..401b317 100644 --- a/NetboxPS/NetboxPS.psd1 +++ b/NetboxPS/NetboxPS.psd1 @@ -12,7 +12,7 @@ RootModule = 'NetboxPS.psm1' # Version number of this module. -ModuleVersion = '1.7.0' +ModuleVersion = '1.7.1' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/NetboxPS/NetboxPS.psm1 b/NetboxPS/NetboxPS.psm1 index 15c2b54..be43730 100644 --- a/NetboxPS/NetboxPS.psm1 +++ b/NetboxPS/NetboxPS.psm1 @@ -517,19 +517,10 @@ function Connect-NetboxAPI { 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!" - - #Write-Verbose "Caching static choices" - #$script:NetboxConfig.Choices.Circuits = Get-NetboxCircuitsChoices - #$script:NetboxConfig.Choices.DCIM = Get-NetboxDCIMChoices # Not completed yet - #$script:NetboxConfig.Choices.Extras = Get-NetboxExtrasChoices - #$script:NetboxConfig.Choices.IPAM = Get-NetboxIPAMChoices - ##$script:NetboxConfig.Choices.Secrets = Get-NetboxSecretsChoices # Not completed yet - ##$script:NetboxConfig.Choices.Tenancy = Get-NetboxTenancyChoices - #$script:NetboxConfig.Choices.Virtualization = Get-NetboxVirtualizationChoices + + $script:NetboxConfig.ContentTypes = Get-NetboxContentType -Limit 500 Write-Verbose "Connection process completed" }