ShouldProcess

심각도 수준: 경고

Description

이 규칙은 선언과 SupportsShouldProcess 콜 간의 ShouldProcess 불일치를 감지합니다. cmdlet이 속성을 선언할 SupportsShouldProcess 때, 메서드도 ShouldProcess 함께 호출해야 합니다.

위반은 다음과 같은 경우에 발생합니다:

  • 함수는 선언하지만 SupportsShouldProcess 호출하지는 않습니다 ShouldProcess
  • 함수는 호출 ShouldProcess 하지만 선언하지 않습니다 SupportsShouldProcess

이 위반을 해결하려면 호출이 ShouldProcess 속성 선언과 SupportsShouldProcess 짝지어지도록 하세요.

자세한 내용은 다음 문서를 참조하세요.

Example

비준수

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
    }
}