1
1
function Email {
2
- [CmdLetBinding (SupportsShouldProcess = $True )]
2
+ [CmdLetBinding ()]
3
3
param (
4
4
[Parameter (Mandatory = $false , Position = 0 )][ScriptBlock ] $Email ,
5
5
[string []] $To ,
@@ -21,9 +21,10 @@ function Email {
21
21
[ValidateSet (' None' , ' OnSuccess' , ' OnFailure' , ' Delay' , ' Never' )] $DeliveryNotifications = ' None' ,
22
22
[string ] $Encoding = ' Unicode' ,
23
23
[string ] $FilePath ,
24
- [bool ] $Supress = $true
24
+ [bool ] $Supress = $true ,
25
+ [switch ] $WhatIf
25
26
)
26
- $StartTime = Start-TimeLog
27
+ $StartTime = [ System.Diagnostics.Stopwatch ]::StartNew()
27
28
$ServerParameters = [ordered ] @ {
28
29
From = $From
29
30
To = $To
@@ -107,13 +108,12 @@ function Email {
107
108
}
108
109
}
109
110
110
- $MailSentTo = " To: $ ( $ServerParameters.To -join ' , ' ) ; CC: $ ( $ServerParameters.CC -join ' , ' ) ; BCC: $ ( $ServerParameters.BCC -join ' , ' ) " .Trim()
111
- if ($pscmdlet.ShouldProcess (" $MailSentTo " , " Email" )) {
112
- $EmailOutput = Send-Email - EmailParameters $ServerParameters - Body ($Body -join ' ' ) - Attachment $Attachments
113
- if (-not $Supress ) {
114
- $EmailOutput
115
- }
111
+ # $MailSentTo = "To: $($ServerParameters.To -join ', '); CC: $($ServerParameters.CC -join ', '); BCC: $($ServerParameters.BCC -join ', ')".Trim()
112
+ $EmailOutput = Send-Email - EmailParameters $ServerParameters - Body ($Body -join ' ' ) - Attachment $Attachments - WhatIf:$WhatIf
113
+ if (-not $Supress ) {
114
+ $EmailOutput
116
115
}
116
+
117
117
$EndTime = Stop-TimeLog - Time $StartTime - Option OneLiner
118
118
Write-Verbose " Email - Time to send: $EndTime "
119
119
}
0 commit comments