Forum Discussion
Powershell script via task scheduler not work as expected
The strange thing with send-message is that if an error occurs, the send-message within the catch path works fine without using the -credential parameter.
For the Start-Transcript and out-file I use an UNC path (just shortened it in the provided code).
E.g.
Start-Transcript -Path "\\edc-derant202\EmployeePic\Scripts\transcript.txt" -Append
$date2 + " - Uploaded picture for " + $mailaddress | Out-File \\edc-derant202\EmployeePic\Scripts\log.txt -append
Seems you have missed the parameter -Body in your inner query. Just provide some content for -Body parameter.
Send-MailMessage -From "o365.service.eu@mydomain.com" -To stefan@mydomain.com -SmtpServer smtp.mydomain.com ` -Subject "Added picture for $mailAddress" -Body "Added picture"
For the Start-Transcript, ensure that the schedule task account has valid permission (write) in the UNC path.
- machineslaveSep 18, 2019Copper Contributor
Thanks a lot.
Just added the -Body parameter and also verified / resolved the permissions of the UNC path.
Now it works properly.