PowerShell 自动给新员工发送欢迎邮件

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

$today = Get-Date
$csvlocation = "d:\Welcome_Letter\newsletter.csv"
$pdflocation = "d:\Welcome_Letter\Reset Password for Global Mial Account.pdf"
$htmbody = (Get-Content d:\Welcome_Letter\1.html | Out-String)
Get-QADUser -searchroot 'contoso.com.cn/Staff/' -IncludedProperties PrimarySMTPAddress |  Where-Object {($_.whenCreated - $today).days -eq "1"} | select name, whenCreated, PrimarySMTPAddress | export-csv $csvlocation -notype -Encoding "UTF8"
import-csv $csvlocation |  ForEach-Object {Send-MailMessage -Subject "Welcome to Join Contoso - $((Get-Date).ToShortDateString())" -Body $htmbody -BodyAsHtml -Attachments $pdflocation -From "welcome@contoso.com" -To $_.PrimarySMTPAddress -Bcc "webmaster@contoso.com"-SmtpServer "Smtp.contoso.cn" -Encoding ([System.Text.Encoding]::UTF8) }