Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Test-Function {
- [OutputType([String])]
- [CmdletBinding(
- SupportsShouldProcess=$true,
- ConfirmImpact="None"
- )]
- param (
- [Parameter(Position=1, Mandatory=$true, ValueFromPipeline=$true)]
- [ValidateNotNullOrEmpty()]
- [string]$Name
- )
- Begin{
- $formats = @{
- "Begin" = "Begin {0}...";
- "Process" = "...processing {0}...";
- "End" = "...ending {0}";
- };
- Write-Verbose -Message ($formats.Begin -f $MyInvocation.MyCommand);
- $date = Get-Date;
- } Process {
- Write-Verbose -Message ($formats.Process -f $MyInvocation.MyCommand);
- if ($pscmdlet.ShouldProcess($Name)) {
- return "Welcome to Hello World $Name on $date";
- }
- } End {
- Write-Verbose -Message ($formats.End -f $MyInvocation.MyCommand);
- }
- }
- "Bob", "Mary" | Test-Function -WhatIf
- "Bob", "Mary" | Test-Function -Confirm
- "Bob", "Mary" | Test-Function -Verbose
- Test-Function -Name "Bob"
Add Comment
Please, Sign In to add comment