PSSA: Fix Command accepts pipeline input but has not defined a process block

This commit is contained in:
Alexis La Goutte 2021-07-23 21:09:06 +02:00
parent 76b891542e
commit 0217808bfc
8 changed files with 104 additions and 88 deletions

View file

@ -13,7 +13,7 @@
function Get-NetboxCircuit { function Get-NetboxCircuit {
<# <#
.SYNOPSIS .SYNOPSIS
Gets one or more circuits Gets one or more circuits
@ -105,27 +105,29 @@ function Get-NetboxCircuit {
[switch]$Raw [switch]$Raw
) )
switch ($PSCmdlet.ParameterSetName) { process {
'ById' { switch ($PSCmdlet.ParameterSetName) {
foreach ($i in $ID) { 'ById' {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits', $i)) 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 $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw 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
}
} }
} }

View file

@ -15,12 +15,12 @@
function New-NetboxCircuit { function New-NetboxCircuit {
[CmdletBinding(ConfirmImpact = 'Low', [CmdletBinding(ConfirmImpact = 'Low',
SupportsShouldProcess = $true)] SupportsShouldProcess = $true)]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
param param
( (
[Parameter(Mandatory = $true, [Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)] ValueFromPipelineByPropertyName = $true)]
[string]$CID, [string]$CID,
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
@ -54,14 +54,16 @@ function New-NetboxCircuit {
[switch]$Raw [switch]$Raw
) )
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits')) process {
$Method = 'POST' $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')) { if ($Force -or $PSCmdlet.ShouldProcess($CID, 'Create new circuit')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
}
} }
} }

View file

@ -85,15 +85,17 @@ function Get-NetboxDCIMDevice {
#endregion Parameters #endregion Parameters
if ($null -ne $Status) { process {
$PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus 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
} }

View file

@ -47,15 +47,17 @@ function Get-NetboxDCIMInterface {
[switch]$Raw [switch]$Raw
) )
if ($null -ne $Form_Factor) { process {
$PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor 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
} }

View file

@ -81,28 +81,30 @@ function Get-NetboxDCIMSite {
[switch]$Raw [switch]$Raw
) )
switch ($PSCmdlet.ParameterSetName) { process {
'ById' { switch ($PSCmdlet.ParameterSetName) {
foreach ($Site_ID in $ID) { 'ById' {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites', $Site_Id)) 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 $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw 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
}
} }
} }

View file

@ -13,7 +13,7 @@
function Get-NetboxVirtualMachine { function Get-NetboxVirtualMachine {
<# <#
.SYNOPSIS .SYNOPSIS
Obtains virtual machines from Netbox. Obtains virtual machines from Netbox.
@ -141,15 +141,17 @@ function Get-NetboxVirtualMachine {
[switch]$Raw [switch]$Raw
) )
if ($null -ne $Status) { process {
$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus 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
} }

View file

@ -14,11 +14,11 @@
function Set-NetboxVirtualMachine { function Set-NetboxVirtualMachine {
[CmdletBinding(ConfirmImpact = 'Medium', [CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)] SupportsShouldProcess = $true)]
param param
( (
[Parameter(Mandatory = $true, [Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)] ValueFromPipelineByPropertyName = $true)]
[uint16]$Id, [uint16]$Id,
[string]$Name, [string]$Name,
@ -50,23 +50,25 @@ function Set-NetboxVirtualMachine {
[switch]$Force [switch]$Force
) )
# if ($null -ne $Status) { # if ($null -ne $Status) {
# $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus # $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")) { if ($Force -or $pscmdlet.ShouldProcess($ID, "Set properties on VM ID")) {
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force' $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
}
} }
} }

View file

@ -13,7 +13,7 @@
function Get-NetboxVirtualMachineInterface { function Get-NetboxVirtualMachineInterface {
<# <#
.SYNOPSIS .SYNOPSIS
Gets VM interfaces Gets VM interfaces
@ -84,11 +84,13 @@ function Get-NetboxVirtualMachineInterface {
[switch]$Raw [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
}
} }