Guest User

Untitled

a guest
Dec 17th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. function Test-Function {
  2. [OutputType([String])]
  3. [CmdletBinding(
  4. SupportsShouldProcess=$true,
  5. ConfirmImpact="None"
  6. )]
  7. param (
  8. [Parameter(Position=1, Mandatory=$true, ValueFromPipeline=$true)]
  9. [ValidateNotNullOrEmpty()]
  10. [string]$Name
  11. )
  12. Begin{
  13. $formats = @{
  14. "Begin" = "Begin {0}...";
  15. "Process" = "...processing {0}...";
  16. "End" = "...ending {0}";
  17. };
  18. Write-Verbose -Message ($formats.Begin -f $MyInvocation.MyCommand);
  19. $date = Get-Date;
  20. } Process {
  21. Write-Verbose -Message ($formats.Process -f $MyInvocation.MyCommand);
  22. if ($pscmdlet.ShouldProcess($Name)) {
  23. return "Welcome to Hello World $Name on $date";
  24. }
  25. } End {
  26. Write-Verbose -Message ($formats.End -f $MyInvocation.MyCommand);
  27. }
  28. }
  29.  
  30. "Bob", "Mary" | Test-Function -WhatIf
  31. "Bob", "Mary" | Test-Function -Confirm
  32. "Bob", "Mary" | Test-Function -Verbose
  33.  
  34. Test-Function -Name "Bob"
Add Comment
Please, Sign In to add comment