Skip to content

Instantly share code, notes, and snippets.

@disouzam
Forked from adbertram/powershell_tip
Created June 5, 2024 15:26
Show Gist options
  • Save disouzam/bd86783be8460bb78bddae3b96d10f92 to your computer and use it in GitHub Desktop.
Save disouzam/bd86783be8460bb78bddae3b96d10f92 to your computer and use it in GitHub Desktop.
# Long command with many parameters all on one line
Send-MailMessage -From "admin@example.com" -To "user@example.com" -Subject "Test Email" -Body "This is a test email." -SmtpServer "smtp.example.com" -Port 587 -UseSsl -Credential (Get-Credential) -Attachments "C:\path\to\file.txt" -Priority High -DeliveryNotificationOption OnSuccess, OnFailure
# Equivalent command using splatting for readability
$mailParams = @{
From = "admin@example.com"
To = "user@example.com"
Subject = "Test Email"
Body = "This is a test email."
SmtpServer = "smtp.example.com"
Port = 587
UseSsl = $true
Credential = (Get-Credential)
Attachments = "C:\path\to\file.txt"
Priority = "High"
DeliveryNotificationOption = "OnSuccess, OnFailure"
}
Send-MailMessage @mailParams
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment