From 32a417fd2a648dd5cde2ca0ac7659db614ef35cc Mon Sep 17 00:00:00 2001 From: SheffSix Date: Mon, 13 Mar 2023 11:50:41 +0000 Subject: [PATCH] Fixing #41 --- .../Interfaces/Add-NetboxDCIMInterface.ps1 | 21 +++++++---- .../Interfaces/Get-NetboxDCIMInterface.ps1 | 6 ++-- .../Interfaces/Set-NetboxDCIMInterface.ps1 | 36 ++++++++++++------- 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/Functions/DCIM/Interfaces/Add-NetboxDCIMInterface.ps1 b/Functions/DCIM/Interfaces/Add-NetboxDCIMInterface.ps1 index 4fa4f79..9fdfd55 100644 --- a/Functions/DCIM/Interfaces/Add-NetboxDCIMInterface.ps1 +++ b/Functions/DCIM/Interfaces/Add-NetboxDCIMInterface.ps1 @@ -1,5 +1,6 @@  -function Add-NetboxDCIMInterface { +function Add-NetboxDCIMInterface +{ [CmdletBinding()] [OutputType([pscustomobject])] param @@ -37,24 +38,30 @@ function Add-NetboxDCIMInterface { [uint16[]]$Tagged_VLANs ) - if (-not [System.String]::IsNullOrWhiteSpace($Mode)) { - $PSBoundParameters.Mode = switch ($Mode) { - 'Access' { + if (-not [System.String]::IsNullOrWhiteSpace($Mode)) + { + $PSBoundParameters.Mode = switch ($Mode) + { + 'Access' + { 100 break } - 'Tagged' { + 'Tagged' + { 200 break } - 'Tagged All' { + 'Tagged All' + { 300 break } - default { + default + { $_ } } diff --git a/Functions/DCIM/Interfaces/Get-NetboxDCIMInterface.ps1 b/Functions/DCIM/Interfaces/Get-NetboxDCIMInterface.ps1 index 730e776..0045afc 100644 --- a/Functions/DCIM/Interfaces/Get-NetboxDCIMInterface.ps1 +++ b/Functions/DCIM/Interfaces/Get-NetboxDCIMInterface.ps1 @@ -1,5 +1,6 @@  -function Get-NetboxDCIMInterface { +function Get-NetboxDCIMInterface +{ [CmdletBinding()] [OutputType([pscustomobject])] param @@ -35,7 +36,8 @@ function Get-NetboxDCIMInterface { [switch]$Raw ) - process { + process + { $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces')) $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters diff --git a/Functions/DCIM/Interfaces/Set-NetboxDCIMInterface.ps1 b/Functions/DCIM/Interfaces/Set-NetboxDCIMInterface.ps1 index 566c1a0..dd35b17 100644 --- a/Functions/DCIM/Interfaces/Set-NetboxDCIMInterface.ps1 +++ b/Functions/DCIM/Interfaces/Set-NetboxDCIMInterface.ps1 @@ -1,5 +1,6 @@  -function Set-NetboxDCIMInterface { +function Set-NetboxDCIMInterface +{ [CmdletBinding(ConfirmImpact = 'Medium', SupportsShouldProcess = $true)] [OutputType([pscustomobject])] @@ -40,33 +41,42 @@ function Set-NetboxDCIMInterface { [uint16[]]$Tagged_VLANs ) - begin { - if (-not [System.String]::IsNullOrWhiteSpace($Mode)) { - $PSBoundParameters.Mode = switch ($Mode) { - 'Access' { + begin + { + if (-not [System.String]::IsNullOrWhiteSpace($Mode)) + { + $PSBoundParameters.Mode = switch ($Mode) + { + 'Access' + { 100 break } - 'Tagged' { + 'Tagged' + { 200 break } - 'Tagged All' { + 'Tagged All' + { 300 break } - default { + default + { $_ } } } } - process { - foreach ($InterfaceId in $Id) { + process + { + foreach ($InterfaceId in $Id) + { $CurrentInterface = Get-NetboxDCIMInterface -Id $InterfaceId -ErrorAction Stop $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces', $CurrentInterface.Id)) @@ -75,13 +85,15 @@ function Set-NetboxDCIMInterface { $URI = BuildNewURI -Segments $Segments - if ($Force -or $pscmdlet.ShouldProcess("Interface ID $($CurrentInterface.Id)", "Set")) { + if ($Force -or $pscmdlet.ShouldProcess("Interface ID $($CurrentInterface.Id)", "Set")) + { InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH } } } - end { + end + { } } \ No newline at end of file