|
30 | 30 | |
31 | 31 | .PARAMETER SentPath |
32 | 32 | The folder in which emails that were successfully sent are stored for a specified time before being deleted. |
| 33 | +
|
| 34 | + .PARAMETER FailedPath |
| 35 | + The path where mails that could repeatedly not be sent are moved to. |
33 | 36 | |
34 | 37 | .PARAMETER DaemonUser |
35 | 38 | The user to grant permissions needed to function as the Daemon account. |
|
41 | 44 | |
42 | 45 | .PARAMETER MailSentRetention |
43 | 46 | The time to keep successfully sent emails around. |
| 47 | +
|
| 48 | + .PARAMETER MailAbandonThreshold |
| 49 | + How long we attempt to send an email before abandoning it and moving it to -FailedPath. |
| 50 | +
|
| 51 | + .PARAMETER MailFailedRetention |
| 52 | + How long we keep an abandoned email around before removing it entirely. |
44 | 53 | |
45 | 54 | .PARAMETER SmtpServer |
46 | 55 | The mailserver to use for sending emails. |
|
59 | 68 | .PARAMETER UseSSL |
60 | 69 | Use SSL for sending emails. |
61 | 70 |
|
| 71 | + .PARAMETER NoLogging |
| 72 | + Disables logging. |
| 73 | + Unless specified, this setup step will also prepare the windows eventlog by creating a dedicated eventlog for MailDaemon. |
| 74 | +
|
62 | 75 | .EXAMPLE |
63 | 76 | PS C:\> Install-MDDaemon -ComputerName DC1, DC2, DC3 -TaskUser $cred -DaemonUser "DOMAIN\MailDaemon" -SmtpServer 'mail.domain.org' -SenderDefault 'daemon@domain.org' -RecipientDefault 'helpdesk-t2@domain.org' |
64 | 77 | |
|
85 | 98 |
|
86 | 99 | [string] |
87 | 100 | $SentPath, |
| 101 | + |
| 102 | + [string] |
| 103 | + $FailedPath, |
88 | 104 |
|
89 | 105 | [string] |
90 | 106 | $DaemonUser, |
|
94 | 110 |
|
95 | 111 | [Timespan] |
96 | 112 | $MailSentRetention, |
| 113 | + |
| 114 | + [Timespan] |
| 115 | + $MailAbandonThreshold, |
| 116 | + |
| 117 | + [Timespan] |
| 118 | + $MailFailedRetention, |
97 | 119 |
|
98 | 120 | [string] |
99 | 121 | $SmtpServer, |
|
108 | 130 | $RecipientDefault, |
109 | 131 |
|
110 | 132 | [switch] |
111 | | - $UseSSL |
| 133 | + $UseSSL, |
| 134 | + |
| 135 | + [switch] |
| 136 | + $NoLogging |
112 | 137 | ) |
113 | 138 |
|
114 | 139 | begin { |
|
161 | 186 | #region Setup Task Configuration |
162 | 187 | if (-not $NoTask) { |
163 | 188 | $action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-NoProfile -Command Invoke-MDDaemon" |
| 189 | + if ($NoLogging) { $action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-NoProfile -Command Invoke-MDDaemon -NoLogging" } |
164 | 190 | $triggers = @() |
165 | 191 | $triggers += New-ScheduledTaskTrigger -AtStartup -RandomDelay "00:15:00" |
166 | 192 | $triggers += New-ScheduledTaskTrigger -At "00:00:00" -Daily |
|
184 | 210 | #endregion Setup Task Configuration |
185 | 211 |
|
186 | 212 | #region Preparing Parameters |
187 | | - $parameters = $PSBoundParameters | ConvertTo-PSFHashtable -Include 'PickupPath', 'SentPath', 'MailSentRetention', 'SmtpServer', 'SenderDefault', 'RecipientDefault', 'UseSSL' |
| 213 | + $parameters = $PSBoundParameters | ConvertTo-PSFHashtable -Include 'PickupPath', 'SentPath', 'FailedPath', 'MailSentRetention', 'MailAbandonThreshold', 'MailFailedRetention', 'SmtpServer', 'SenderDefault', 'RecipientDefault', 'UseSSL' |
188 | 214 |
|
189 | 215 | $paramMainInstallCall = @{ |
190 | 216 | ArgumentList = $parameters |
|
246 | 272 | if ($TaskUser) { $parametersSave['AccessAccount'] = $TaskUser } |
247 | 273 | Save-MDCredential @parametersSave |
248 | 274 |
|
249 | | - $parametersInvoke = @{ $parametersInvoke['ComputerName'] = $ComputerName } |
| 275 | + $parametersInvoke = @{ ComputerName = $ComputerName } |
| 276 | + if ($Credential) { $parametersInvoke['Credential'] = $Credential } |
250 | 277 | Invoke-PSFCommand @parametersInvoke -ScriptBlock { |
251 | 278 | Set-MDDaemon -SenderCredentialPath "C:\ProgramData\PowerShell\MailDaemon\senderCredentials.clixml" |
252 | 279 | } |
253 | 280 | } |
254 | 281 | #endregion Securely store credentials |
| 282 | + |
| 283 | + #region Setup Logging |
| 284 | + if (-not $NoLogging) { |
| 285 | + Invoke-PSFCommand @parametersInvoke -ScriptBlock { |
| 286 | + if ($PSVersionTable.PSVersion.Major -gt 5 -and -not $IsWindows) { return } |
| 287 | + Set-PSFLoggingProvider -Name eventlog -InstanceName MailDaemonInvoke -LogName MailDaemon -Source MailDaemon -Enabled $true -Wait |
| 288 | + Write-PSFMessage -Message "Setting up MailDaemon logging" |
| 289 | + Disable-PSFLoggingProvider -Name eventlog -InstanceName MailDaemonInvoke |
| 290 | + } |
| 291 | + } |
| 292 | + #endregion Setup Logging |
255 | 293 |
|
256 | 294 | #region Setup Task |
257 | 295 | if (-not $NoTask) { |
258 | | - foreach ($computerObject in $ComputerName) { |
259 | | - if ($ComputerName.Type -like 'CimSession') { $parametersRegister["CimSession"] = $computerObject.InputObject } |
260 | | - elseif (-not $ComputerName.IsLocalhost) { $parametersRegister["CimSession"] = $ComputerName } |
261 | | - |
262 | | - $null = Register-ScheduledTask @parametersRegister |
263 | | - } |
| 296 | + Invoke-PSFCommand @parametersInvoke -ScriptBlock { |
| 297 | + param ($ParametersRegister) |
| 298 | + |
| 299 | + $taskObject = Get-ScheduledTask -TaskName $ParametersRegister.TaskName -ErrorAction Ignore |
| 300 | + if ($taskObject) { $taskObject | Unregister-ScheduledTask } |
| 301 | + |
| 302 | + $null = Register-ScheduledTask @ParametersRegister |
| 303 | + } -ArgumentList $parametersRegister |
264 | 304 | } |
265 | 305 | #endregion Setup Task |
266 | 306 | } |
|
0 commit comments