إشعار
يتطلب الوصول إلى هذه الصفحة تخويلاً. يمكنك محاولة تسجيل الدخول أو تغيير الدلائل.
يتطلب الوصول إلى هذه الصفحة تخويلاً. يمكنك محاولة تغيير الدلائل.
مستوى الخطورة : التحذير
Description
تكتشف هذه القاعدة عدم التوافق بين SupportsShouldProcess التصريحات والنداءات ShouldProcess .
عندما يعلن cmdlet عن الخاصية SupportsShouldProcess ، يجب أن يستدعي أيضا الطريقة ShouldProcess .
تحدث الانتهاكات عندما:
- الدالة تعلن
SupportsShouldProcessلكنها لا تناديShouldProcess - دالة ما تستدعي
ShouldProcessلكنها لا تعلنSupportsShouldProcess
لإصلاح هذا الانتهاك، تأكد من أن ShouldProcess المكالمات مرتبطة بإعلان SupportsShouldProcess السمات.
لمزيد من المعلومات، راجع المقالات التالية:
- about_Functions_Advanced_Methods
- about_Functions_CmdletBindingAttribute
- كل ما أردت معرفته عن ShouldProcess
مثال
غير متوافق
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
}
}