$path = "C:\Users\IT.PC\Desktop\报警\file\"
$nMsg = "
<br>您好!</br>
<br>附件是您企业的用户邮箱状态报告:</br>
"
$date = get-date -format yyyy-MM-dd #获取当前日期
$nSmtpserver = "smtp.163.com"
$nFrom = "testuser@xxx.com"
$nTo = "zhangsan@xxx.com"
$nSubject = "最新检测报告, $date"
$UserName = "testuser@xxx.com" #定义管理员账户名称
$Password = ConvertTo-SecureString xxxxxx -AsPlainText –Force
$cred = New-Object System.Management.Automation.PSCredential($UserName,$Password)
cd $path
Get-ChildItem $path| ForEach-Object -Process{
if($_ -is [System.IO.DirectoryInfo]){
$flodername = $_.name
$newpath = $path+$flodername+"\"
Get-ChildItem $newpath| Where-Object { $_.Extension -eq '.pdf' }
if($? -eq "True"){
$argument = "a -ep "+ $flodername+$date+".rar "+$newpath
write-host $argument
#start-process "C:\Program Files\WinRAR\WinRAR" -ArgumentList $argument -NoNewWindow -Wait
$nAttachments = $flodername+$date+".rar"
#send-mailmessage -From $nFrom -To $nTo -body $nMsg -Subject $nSubject -Attachments $nAttachments -SmtpServer $nSmtpserver -Credential $cred -Encoding ([System.Text.Encoding]::UTF8)
write-host "完成,已发送给 $nTo"
}
}
}