-file c:\scripts\test.ps1 > c:\Temp\test.log
NO quotes. The command line des not understand *> syntax.
You are better of generating a file in the PS1 script. The output from your commands are not available as written.
The sleep commands are pointless. The service commands will not return until the service has changed.
There are numerous syntax errors in your code. If you would correctly write, format and test your code you would see most of the issues.
Here is how to post code in this forum:
$logfile = 'c:\Temp\test.log'
$mailprops = @{
From = 'operating.system@abc.com'
To = 'asdf@abc.com'
Subject = 'test'
Attachment = $logfile
SmtpServer = '127.0.0.1'
}
'Stopping services' | Out-File $logfile
Stop-Service '3456','2354'
'Services stopped' | Out-File $logfile -append
Restart-computer QY34 -Force
'Remote computer sent restart command' | Out-File $logfile -append
Send-MailMessage @mailprops
Of course there are a dozen other technical things you will need to learn to write a script and run it as a task. If you are trying to restart the computer running the task then that will not work.
\_(ツ)_/