Skip to main content

Email

Email

Configuration options

OptionTypeMandatoryDefaultDescription
LevelStringNoDefault LevelDefines the lowest logging level to logged
FormatStringNoDefault FormatDefines a custom format for the target
SMTPServerStringYesN/ASMTP server FQDN
FromStringYesN/AFrom address
ToStringYesN/AA string of recipients
SubjectStringNoN/AEmail subject. Supports formatting and expansion
AttachmentsStringNoN/APath to the desired file to attach
CredentialPSCredentialNoN/AIf your server uses authentication
PortIntNo25Set the SMTP server's port
UseSslBooleanNoN/AUse encrypted transport to SMTP server
PrintExceptionBooleanNoN/APrint stacktrace in the body

Example

> Add-LoggingTarget -Name Email -Configuration @{
SMTPServer = 'smtp.contoso.com'
From = 'PSLogs <pslogs@contoso.com>'
To = 'test@contoso.com,robin@hood.eu'
Subject = '[%{level:-7}] %{message}'
Attachments = 'C:\Path\To\StateSnapshot.xml'
Credential = $cred
Level = 'ALERT'
Port = 587
UseSsl = $true
PrintException = $true
}