Notitie
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen u aan te melden of de directory te wijzigen.
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen de mappen te wijzigen.
ernstniveau: waarschuwing
Beschrijving
Deze regel detecteert mismatches tussen SupportsShouldProcess verklaringen en ShouldProcess calls.
Wanneer een cmdlet het SupportsShouldProcess attribuut declareert, moet het ook de ShouldProcess methode aanroepen.
Overtredingen vinden plaats wanneer:
- Een functie declareert
SupportsShouldProcessmaar roept niet aanShouldProcess - Een functie roept
ShouldProcessaan, maar declareert nietSupportsShouldProcess
Om deze overtreding te verhelpen, zorg ervoor dat ShouldProcess aanroepen worden gekoppeld aan de SupportsShouldProcess attribuutdeclaratie.
Zie de volgende artikelen voor meer informatie:
- over_Functies_Geavanceerde_Methoden
- about_Functions_CmdletBindingAttribute
- Alles wat je wilde weten over ShouldProcess
Voorbeeld
Niet conform
function Set-File
{
[CmdletBinding(SupportsShouldProcess=$true)]
Param
(
# Path to file
[Parameter(Mandatory=$true)]
$Path
)
'String' | Out-File -FilePath $Path
}
Compliant
function Set-File
{
[CmdletBinding(SupportsShouldProcess=$true)]
Param
(
# Path to file
[Parameter(Mandatory=$true)]
$Path,
[Parameter(Mandatory=$true)]
[string]$Content
)
if ($PSCmdlet.ShouldProcess($Path, ("Setting content to '{0}'" -f $Content)))
{
$Content | Out-File -FilePath $Path
}
else
{
# Code that should be processed if doing a WhatIf operation
# Must NOT change anything outside of the function / script
}
}