Powershell sends emails when run interactively, but not when it runs automatically in Task Scheduler
Hello.
I have written a PowerShell script that is designed to send output via email to its intended recipient. When run by the Task Scheduler utility, the Administrator user account is used, whether or not the account is logged into the system, and run with the highest privileges. The script is run using the following command syntax:
powershell -executionpolicy bypass -file C:\Scripts\check_disk_space.ps1
The text of the script is the following:
Powershell -executionpolicy bypass -File C:\Scripts\disk_space_check.ps1
. C:\Scripts\disk_space_check.ps1
Get-DiskSpaceReport -ComputerList C:\Scripts\server.txt -To ******@partners.org -From ******@partners.org -SMTP smtp.partners.org
The text of the script is the following:
The command within the script that accomplishes this is the following:
Get-DiskSpaceReport -ComputerList C:\Scripts\server.txt -To <email address> -From <email address> -SMTP <serverhostname>
When I run the script interactively, the email is sent without issue. However, when the script is run through the Task Scheduler, it appears the script ran successfully, but no email is received by the recipient. Is there another command that I need to include in order for this to work?