Skip to content

Commit 2fbeb71

Browse files
committed
Add note about $WhatIf
1 parent b68d9bd commit 2fbeb71

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

reference/docs-conceptual/learn/deep-dives/everything-about-shouldprocess.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ Notice that I did not create a parameter called `-WhatIf`. Specifying `SupportsS
141141
automatically creates it for us. When we specify the `-WhatIf` parameter on `Test-ShouldProcess`,
142142
some things we call also perform `-WhatIf` processing.
143143

144+
> [!NOTE]
145+
> When you use `SupportsShouldProcess`, PowerShell doesn't add the `$WhatIf` variable to the
146+
> function. You don't need to check the value of `$WhatIf` because the `ShouldProcess()` method
147+
> takes care of that for you.
148+
144149
### Trust but verify
145150

146151
There's some danger here trusting that everything you call inherits `-WhatIf` values. For the rest
@@ -537,7 +542,7 @@ function Test-ShouldProcess {
537542

538543
We add our own `-Force` switch as a parameter. The `-Confirm` parameter is automatically added when
539544
using `SupportsShouldProcess` in the `CmdletBinding`. However, when you use `SupportsShouldProcess`,
540-
PowerShell doesn't add the `$Confirm` parameter to the function. If you are running in Strict Mode
545+
PowerShell doesn't add the `$Confirm` variable to the function. If you are running in Strict Mode
541546
and try to use the `$Confirm` variable before it has been defined, you get an error. To avoid the
542547
error you can use `$PSBoundParameters` to test if the parameter was passed by the user.
543548

0 commit comments

Comments
 (0)