You may start with learning the very basics of Powershell first. The cmdlet to send a mail message is Send-MailMessage. Please read the complete help including the examples to learn how to use it.
BTW: Did you follow the tip TheMadTechnician gave you in the comments on StackOverflow?
A better approach would be to edit what is being executed in \Receive Orders to send the email when it starts so it’s the same process. The next would be to make an email task that’s a dependency for \Receive Orders, something like this:
It’s a scheduled task, so you could also just run the email at the same time on the same schedule. Checking the status of the running service is typically looping continually to check the state which would be running all of the time.
The comment that he left for me has nothing to do with the problem I am having. I don’t care about the time when the job is running or if its off by 30 seconds, I just want to get a notification when its running.
‘Receive Orders’ job runs for about 2 minutes. So for example job starts at 10:00 am should finish at 10:02. At 10:04 my “Check Receive Orders” kicks off and checks if the “Receive Orders” is still running. If it is send me an email if it doesn’t doesn’t send me an email.
I guess what Im asking for is how do phrase that
I just don’t know what to put in front of all of this to get the result.
As suggested you should put the code to send an email into the task. To send a mail message you could use the cmdlet Send-MailMessage. … maybe like this:
$SendMailMessageProps = @{
From = ‘test@test.com’
To = ‘test@test.com’
SMTPServer = ‘smtp.server.com’
Subject = ‘Receive Orders Running’
Body = ‘Job Running.’
}
This send an email but it sends it when the job is in ready or running state.
To clarify I am checking on an existing Task Scheduler job with a new Task Scheduler job. Two different Tasks.
PS C:\Windows\system32> schtasks /query /fo LIST /tn ‘\Receive Orders’
$SendMailMessageProps = @{
From = ‘test@test.com’
To = ‘test@test.com’
SMTPServer = ‘smtp.test.com’
Subject = ‘Receive Orders Running’
Body = ‘Job Running.’
}
Send-MailMessage @SendMailMessageProps
Folder:
HostName: test-VM
TaskName: \Receive Orders
Next Run Time: 2/26/2020 9:40:00 AM
Status: Ready - It should look at this field and only email when Running
Logon Mode: Interactive/Background
Please - format your code as code here in the forum using the code tag button named “PRE”. Thanks. And please post the complete output you get with the command
Get-ScheduledTask -name ‘Receive Orders’
If you get the output for the desired scheduled task you can “extract” the status with this piece of code:
(Get-ScheduledTask -name ‘Receive Orders’).state
You can use this to create a condition to check for the state and send an email if the state is what you expect.
If you don’t know how to create a condition I repeat my suggestion from my first reply. Additionally you should read the help for about_if.