15 분마다 실행되는 Excel 보고서를 추출하여 파일 공유로 복사하고 이름을 기반으로 다른 메일 그룹에 전자 메일을 보내는 스크립트가 있습니다 보고서의Powershell 스크립트는 변수 값 대신 True를 반환합니다.
15 분 안에 두 개 이상의 보고서가 폴더로 다운로드되면 스크립트가 정상적으로 작동하고 전자 메일의 보고서 이름과 함께 올바르게 전자 메일을 보냅니다.
문제는 15 분 동안 하나의 보고서 만 다운로드되고 스크립트가 여전히 작동하고 전자 메일을 보내는 경우 전자 메일 본문의 보고서 이름 대신 True입니다.
$downloadTemp = 'C:\Test\'
# List the files in the Temporary download folder
$files = (Get-ChildItem $downloadTemp -name)
# Set the Creation date
$exists = (Get-ChildItem $downloadTemp | Measure-Object).Count
If ($exists -gt 0) {Get-Item $downloadTemp | % {$_.CreationTime = (Get-Date)}
}
# Look for Specific reports
$DailyOpen = $files -Like "Daily Open*"
$DailyProduct = $files -Like "Daily Product*"
$DailyRaised = $files -Like "Daily Raised*"
#More variables
$compareDate = (Get-Date).AddMinutes(-15)
$diff = ((Get-Item $downloadTemp).CreationTime)
If ($diff -gt $compareDate) {
If ([bool]$DailyOpen -eq $True) {
$body = "<HTML><HEAD><META http-equiv=""Content-Type"" content=""text/html; charset=iso-8859-1"" /><TITLE></TITLE></HEAD>"
$body += "<BODY bgcolor=""#FFFFFF"" style=""font-size: Small; font-family: CALIBRI; color: #000000""><P>"
$body += "Hi All<br><br>"
$body += "This is an email to let you know that a new report " + $DailyOpen + " has arrived in<br><br>"
$body += "\\{fileshare}\"
Send-MailMessage -To "" -From "" -Subject "New Daily Open Complaints Report Notification" -bodyashtml -Body $body -SmtpServer ""
}
If ([bool]$DailyProduct -eq $True) {
$body = "<HTML><HEAD><META http-equiv=""Content-Type"" content=""text/html; charset=iso-8859-1"" /><TITLE></TITLE></HEAD>"
$body += "<BODY bgcolor=""#FFFFFF"" style=""font-size: Small; font-family: CALIBRI; color: #000000""><P>"
$body += "Hi All<br><br>"
$body += "This is an email to let you know that a new report " + $DailyProduct + " has arrived in<br><br>"
$body += "\\{fileshare}\"
Send-MailMessage -To "" -From "" -Subject "New Daily Product Conversions Report Notification" -bodyashtml -Body $body -SmtpServer ""
}
#More If statements here. 1 for every report variable used.
}