I´ve modified a script that is searching for today’s file.
If the file of today’s exist an e-mail is sent.
But no matter of how i try I cant format the e-mail message with bold headline and with Arial fonts with yellow background color.
Hope someone can guide me further?
Here´s the code:
$Directories = "E:\Source"
$DestDirectory = "E:\Destination"
#$OtherDirectory = "E:\Test1"
#$TodaysDirectory = "E:\Test2"
$ThisDay = [datetime]::Today
$OtherFiles = 0
$TodaysFiles = 0
Get-ChildItem $directories |
ForEach-Object{
if ($_.Length -eq 0 -and $_.CreationTime.Date -ne $ThisDay){ # What about non-zero length files?
$OtherFiles++
Copy-Item "E:\Source\*.txt" -Destination "E:\Destination"
}
elseif($_.Length -eq 0 -and $_.CreationTime.Date -eq $ThisDay){ # What about non-zero length files?
$TodaysFiles++
Copy-Item "E:\Source\*.txt" -Destination $DestDirectory
}
}
if (-not $TodaysFiles){
Clear-Host
$body = "No files are found from today, and $OtherFiles old files were found"
Write-Host $body
Send-MailMessage -To forename.lastname@domain.com -From server01@domain.com -Subject "Something wrong" -Body $body -SmtpServer smtp1@domain.com
}
elseif($OtherFiles){
Clear-Host
$body = "found $OtherFiles old files, and $TodaysFiles current files"
Write-Host $body
Send-MailMessage -To forename.lastname@domain.com -From server01@domain.com -Subject "Something wrong" -Body $body -SmtpServer smtp1@domain.com
}
else{
Clear-Host
$body = "$TodaysFiles are found from today, and $OtherFiles old files were also found"
Write-Host $body
Get-ChildItem $DestDirectory | Where {-NOT $_.PSIsContainer} | foreach {$_.fullname} |
send-mailmessage -from "Daily Reporting <server01@domain.com>" -to "Forename Lastname <forename.lastname@domain.com>" -subject "Daily Reports" -SmtpServer smtp1@domain.com -Body "Here are the daily research files for your review"
Here´s the source of the script: Powershell check files today in a directory - Microsoft Q&A