This piece of code works perfectly well when I run in powershell-sends an email along with the attachment.But when I schedule it in a task scheduler it does send an email.
send-mailmessage -from "email@example.com" -to "firstname.lastname@example.org", "email@example.com" -bcc firstname.lastname@example.org
-subject "Updates $(Get-Date -format 'g')" -body "Hello YourName, `n Attached are the Updates `n Thanks `n MyName `n `n `n `n This email is scheduled to run every Sunday @12:00AM " -Attachment "C:\Users\myname\Desktop\WUpdates\WUpdates.xlsx" -smtpServer smtp.qwerty.org
Task Scheduler properties :
General - abc
Author - c\myname
Change user/group - abc\sqlenter
Run whether user is logged in or not
Run with hishest privileges
Trigger:Weekly once at 6:00AM
Add arguments: -ExecutionPolicy Bypass -file "C:\Users\myName\Desktop\WUpdates\AWUES.ps1"
AWUES.ps1 has the path for the attachment excel file.
Any help is appreciated.