Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):
  2.  
  3. function Test-ShouldProcess
  4. {
  5. [CmdletBinding(SupportsShouldProcess = $true)]
  6. PARAM (
  7. [Parameter(ValueFromPipeline = $true)]
  8. $InputObject
  9. )
  10.  
  11. PROCESS
  12. {
  13. if ($PSCmdlet.ShouldProcess($InputObject, "Do stuff to it"))
  14. {
  15. Write-Host "Doing stuff to $InputObject"
  16. Test-ShouldProcess_InnerFunc -InputObject $InputObject
  17. }
  18. }
  19. }
  20.  
  21. function Test-ShouldProcess_InnerFunc
  22. {
  23. [CmdletBinding(SupportsShouldProcess = $true)]
  24. PARAM (
  25. [Parameter(ValueFromPipeline = $true)]
  26. $InputObject
  27. )
  28.  
  29. PROCESS
  30. {
  31. if ($PSCmdlet.ShouldProcess($InputObject, "Do internal stuff to it"))
  32. {
  33. Write-Host "Doing internal stuff to $InputObject"
  34. }
  35. }
  36. }
  37.  
  38. "item1", "item2" | Test-ShouldProcess -Confirm
  39.  
  40. Confirm
  41. Are you sure you want to perform this action?
  42. Performing the operation "Do stuff to it" on target "item1".
  43. [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): A
  44. Doing stuff to item1
  45.  
  46. Confirm
  47. Are you sure you want to perform this action?
  48. Performing the operation "Do internal stuff to it" on target "item1".
  49. [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): A
  50. Doing internal stuff to item1
  51. Doing stuff to item2
  52.  
  53. Confirm
  54. Are you sure you want to perform this action?
  55. Performing the operation "Do internal stuff to it" on target "item2".
  56. [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): A
  57. Doing internal stuff to item2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement