Not
Bu sayfaya erişim yetkilendirme gerektiriyor. Oturum açmayı veya dizinleri değiştirmeyi deneyebilirsiniz.
Bu sayfaya erişim yetkilendirme gerektiriyor. Dizinleri değiştirmeyi deneyebilirsiniz.
Şiddet Seviyesi: Uyarı
Description
Bu kural, beyanlar ve SupportsShouldProcess aramalar arasındaki ShouldProcess uyumsuzlukları tespit eder.
Bir cmdlet özniteliği SupportsShouldProcess ilan ettiğinde, aynı zamanda metodu ShouldProcess da çağırmalıdır.
İhlaller şu durumlarda meydana gelir:
- Bir fonksiyon ilan
SupportsShouldProcesseder ama çağırmazShouldProcess - Bir fonksiyon çağırır
ShouldProcessama bildirmezSupportsShouldProcess
Bu ihlali düzeltmek için, çağrıların öznitelik bildirgesiyle ShouldProcess eşleştirildiğinden emin SupportsShouldProcess olun.
Daha fazla bilgi için aşağıdaki makaleleri inceleyin:
- İşlevler_Hakkında_Gelişmiş_Yöntemler
- Functions_CmdletBindingAttribute Hakkında
- ShouldProcess hakkında bilmek istediğiniz her şey
Example
Standartlara Uygun Değil
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
}
}