يجب المعالجة

مستوى الخطورة : التحذير

Description

تكتشف هذه القاعدة عدم التوافق بين SupportsShouldProcess التصريحات والنداءات ShouldProcess . عندما يعلن cmdlet عن الخاصية SupportsShouldProcess ، يجب أن يستدعي أيضا الطريقة ShouldProcess .

تحدث الانتهاكات عندما:

  • الدالة تعلن SupportsShouldProcess لكنها لا تنادي ShouldProcess
  • دالة ما تستدعي ShouldProcess لكنها لا تعلن SupportsShouldProcess

لإصلاح هذا الانتهاك، تأكد من أن ShouldProcess المكالمات مرتبطة بإعلان SupportsShouldProcess السمات.

لمزيد من المعلومات، راجع المقالات التالية:

مثال

غير متوافق

function Set-File
{
    [CmdletBinding(SupportsShouldProcess=$true)]
    Param
    (
        # Path to file
        [Parameter(Mandatory=$true)]
        $Path
    )
    'String' | Out-File -FilePath $Path
}

متوافقه

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