I have a task scheduled on a Windows 10 computer to run our billing at night. The billing program creates a log file. The file is definitely closed at the end of the billing program. The second action of the task is to use Powershell to email the log to the relevant people. The action is set up as follows:
Start a Program: Powershell.exe
The arguments added are:
-NoProfile -ExecutionPolicy Bypass -file "C:\Program Files (x86)\AIM Tasks\EmailNightlyBilling.ps1"
EmailNightlyBilling is as follows:
Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin -erroraction silentlyContinue
$file = "C:\Program Files (x86)\AIM Tasks\MPSBillingLog.txt"
$smtpServer = "192.168.1.X"
$att = new-object Net.Mail.Attachment($file)
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = "administrator@domain.com"
$msg.To.Add("user@domain.com")
$msg.Subject = "Nightly Billing Results"
$msg.Body = "Nightly Billing run on old dev computer."
$msg.Attachments.Add($att)
$smtp.Send($msg)
$att.Dispose()
exit
If I create the action in a task where it is the first action, then it runs fine and emails the log file. If I create the action as the second action of the task, I get
Task Scheduler failed to start "\Nightly Billing" task for user "Domain\Administrator". Additional Data: Error Value: 2147943726.
I have this same setup on a Windows Server 2012 and it works fine as the second action. I have no clue why Windows 10 would be any different.