Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):
- function Test-ShouldProcess
- {
- [CmdletBinding(SupportsShouldProcess = $true)]
- PARAM (
- [Parameter(ValueFromPipeline = $true)]
- $InputObject
- )
- PROCESS
- {
- if ($PSCmdlet.ShouldProcess($InputObject, "Do stuff to it"))
- {
- Write-Host "Doing stuff to $InputObject"
- Test-ShouldProcess_InnerFunc -InputObject $InputObject
- }
- }
- }
- function Test-ShouldProcess_InnerFunc
- {
- [CmdletBinding(SupportsShouldProcess = $true)]
- PARAM (
- [Parameter(ValueFromPipeline = $true)]
- $InputObject
- )
- PROCESS
- {
- if ($PSCmdlet.ShouldProcess($InputObject, "Do internal stuff to it"))
- {
- Write-Host "Doing internal stuff to $InputObject"
- }
- }
- }
- "item1", "item2" | Test-ShouldProcess -Confirm
- Confirm
- Are you sure you want to perform this action?
- Performing the operation "Do stuff to it" on target "item1".
- [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): A
- Doing stuff to item1
- Confirm
- Are you sure you want to perform this action?
- Performing the operation "Do internal stuff to it" on target "item1".
- [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): A
- Doing internal stuff to item1
- Doing stuff to item2
- Confirm
- Are you sure you want to perform this action?
- Performing the operation "Do internal stuff to it" on target "item2".
- [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): A
- Doing internal stuff to item2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement