Forum Discussion
Task scheduler not working with powershell
Hi All,
Ive created my first powershell script to automatically send an email with an attachment.
When i run the script in Powershell on its own, it works fine but then when i try to schedule it with task scheduler, it doesnt work?
the script im using is below and below that is the setting im using for task scheduler.
Send-MailMessage -From ‘***********’ -To ‘*********** -Subject "Sending the Attachment from PowerShell" -Body "The body of email goes here." -Attachment "************" -SmtpServer smtp.office365.com -Port 587 -UseSsl -Credential (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "***********", (ConvertTo-SecureString -String "***********" -AsPlainText -Force))
Program/script - C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Add Arguments - "C:\Users\Luke Grevett\Desktop\Powershell Email\Untitled2.ps1"
ive tried loads of ways to do this and nothing works? any help would be greatly appreciated.
2 Replies
- this is my config when i need to call ps from task sched
program
C:\Windows\system32\windowspowershell\v1.0\powershell.exe
arguments
-noprofile -command E:\Path\Script.ps1LukeGrev Returning here to see if you could resolve this