Dear DaBest,
What a great guide on how to achieve this. You're really da best ;-) Malfortunately I have some difficulties achieving this :-(
I can execute the command in a powershell and I receive my email.
The task scheduler executes freefilesync as the domain backup user (being domain admin but being the only one having access to the NAS)
With executing PowerShell as the domain backup user ("Run as different user" accoring to
https://stackoverflow.com/a/44797801; start powershell -credential "" gives me a "frozen" powershell) I can also send/recieve the email
But when having freefilesync running as the domain backup user through the task scheduler, the email is not sent and thus I do receive no notification of my failed backup job. Freefilesync runs fine though. I do not see a trace of this failure in the freefilesync logfile or in the event viewer (but I do not know how to search in there precisely).
Do you have any idea, why the email is not sent through task scheduler? Has it something to do with the "frozen" powershell when executing start powershell -credential "" and providing the backups user credentials?
Any help is much appreciated!
Kindest regards,
Aurel
Edit: I have no environment variables like $PATH in my ps1 file:
$lastfile = gci C:\Backup_FreeFileSync | sort LastWriteTime | select -last 1
$emailattachment = "C:\Backup_FreeFileSync\" + $lastfile
Edit II:
Using the following command in freefilesync helped:
powershell.exe -NoLogo -NonInteractive -ExecutionPolicy Bypass -noexit -noprofile -command C:\Backup_FreeFileSync\sendFFSMail.ps1
As i see it you don´t need to run the powershell as a different user you just have to create the freefilesync task on the task Scheduler and run it as admin (see attached file) if you done everything right on the script there should be nothing more to it...