The following script schedules successfully but will not actually, you know, restart the server.
schtasks /create /tn "restart test" /ru "domain\admin" /rp supersecret /sc once /st 11:35 /tr "PowerShell -command {Restart-Computer -ComputerName server01 -force -wait
Send-MailMessage -From mail1@domain.com -To mail2@domain.com -Subject 'Rebooted' -SmtpServer smtp.domain.com}"
The Task Scheduler event logs show the task completed successfully:
Task Scheduler successfully completed task "\restart test" , instance "{4a8b0e75-eb2f-4be6-918d-7b66473dd344}" , action "C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.EXE" with return code 0.
If I run just the commands within {...}
, it will restart the server and send the notification email.
What am I missing?
EDIT: I am executing this from a Windows 7 laptop with PowerShell 3.0 to a Windows 2012 Server