PSSA: Fix PSUseShouldProcessForStateChangingFunctions

Function New-/Set-... has verb that could change system state. Therefore, the function has to support 'ShouldProcess'
This commit is contained in:
Alexis La Goutte 2021-07-23 21:20:20 +02:00
parent 1ca534b3a4
commit 0d28d3ef01
5 changed files with 52 additions and 36 deletions

View file

@ -13,7 +13,8 @@
function New-NetboxDCIMDevice { function New-NetboxDCIMDevice {
[CmdletBinding()] [CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
#region Parameters #region Parameters
param param
@ -86,5 +87,7 @@ function New-NetboxDCIMDevice {
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($Name, 'Create new Device')) {
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST
} }
}

View file

@ -13,7 +13,8 @@
function Set-NetboxDCIMInterface { function Set-NetboxDCIMInterface {
[CmdletBinding()] [CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
param param
( (
@ -88,9 +89,11 @@ function Set-NetboxDCIMInterface {
$URI = BuildNewURI -Segments $Segments $URI = BuildNewURI -Segments $Segments
if ($Force -or $pscmdlet.ShouldProcess("Interface ID $($CurrentInterface.Id)", "Set")) {
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
} }
} }
}
end { end {

View file

@ -13,6 +13,8 @@
function New-NetboxIPAMPrefix { function New-NetboxIPAMPrefix {
[CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
[CmdletBinding()] [CmdletBinding()]
param param
( (
@ -55,5 +57,7 @@ function New-NetboxIPAMPrefix {
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($Prefix, 'Create new Prefix')) {
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw
} }
}

View file

@ -40,7 +40,8 @@
Additional information about the function. Additional information about the function.
#> #>
[CmdletBinding()] [CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
param param
( (
@ -75,5 +76,7 @@
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($nae, 'Create new Vlan $($vid)')) {
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw
} }
}

View file

@ -13,7 +13,8 @@
function New-NetboxVirtualMachine { function New-NetboxVirtualMachine {
[CmdletBinding()] [CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
param param
( (
@ -61,8 +62,10 @@ function New-NetboxVirtualMachine {
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($name, 'Create new Virtual Machine')) {
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters
} }
}