鸿 网 互 联 www.68idc.cn

当前位置 : 服务器租用 > 服务器相关 > 批处理 > >

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

来源:互联网 作者:佚名 时间:2015-11-13 08:11
每天都有新进员工,根据公司的需求,要给他们每人发一封起草好的欢迎邮件。下面是写出来的代码,请大家指正。 无 $today = Get-Date$csvlocation = "d:\Welcome_Letter\newsletter.csv"$pdflocation = "d:\Welcome_Letter\Reset Password for Global Mial Acc
每天都有新进员工,根据公司的需求,要给他们每人发一封起草好的欢迎邮件。下面是写出来的代码,请大家指正。 <无>
$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) }
网友评论
<