
close
close
In the first part of this series I demonstrated how to create a simple PowerShell scheduled job, where you can take your existing PowerShell scripts and easily run them as scheduled tasks. Today, I want to give you a little more information on what’s happening behind the scenes.
Here are the scheduled jobs that I’ve set up.
The get-scheduledjob cmdlet in Windows PowerShell. (Image Credit: Jeff Hicks)
The scheduled job execution details in Windows PowerShell. (Image Credit: Jeff Hicks)
Task Scheduler. (Image Credit: Jeff Hicks)
The file path for stored scheduled jobs. (Image Credit: Jeff Hicks)
Within each directory for a scheduled job, there’s an associated XML file. (Image Credit: Jeff Hicks)
Using the receive-job PowerShell cmdlet. (Image Credit: Jeff Hicks)
get-scheduledjob "dc service report" | Set-ScheduledJob -MaxResultCount 5
If you know in advance how many results to retain, Register-ScheduledJob also has a MaxResultCount property. Otherwise, you can manually delete job results like any other job.
advertisment
get-job -Name "DC Service Report" | Remove-Job
If you unregister a job, this will not only remove it from the Task Scheduler, but it will also delete all the associated files, which means you will lose any job results. If you need to, you can easily disable a job so that it won’t remove anything.
The Disable-ScheduledJob cmdlet. (Image Credit: Jeff Hicks)
The get-jobtrigger cmdlet in Windows PowerShell. (Image Credit: Jeff Hicks)
get-jobtrigger -Name "DC Service Report" | Set-JobTrigger -Weekly -DaysOfWeek "Monday","Tuesday","Wednesday","Thursday","Friday"
As you can see, this changed the scheduled task.
Our scheduled task has been updated. (Image Credit: Jeff Hicks)
get-scheduledjob "DC Service Report" | Set-ScheduledJob -Credential globomantics\jeff
Ideally, you want to get everything right the first time when you create the scheduled job. But let’s say I want to run this when I log on to my computer and then once again every hour. If you look at help for New-JobTrigger, there is no parameter set that will let me do that. I will have to manually change it in the Task Scheduler.
Editing the trigger in Task Scheduler. (Image Credit: Jeff Hicks)
Our job has failed to run. (Image Credit: Jeff Hicks)
More from Jeff Hicks
advertisment
Petri Newsletters
Whether it’s Security or Cloud Computing, we have the know-how for you. Sign up for our newsletters here.
advertisment
More in PowerShell
Microsoft’s New PowerShell Crescendo Tool Facilitates Native Command-Line Wraps
Mar 21, 2022 | Rabia Noureen
Most popular on petri
Log in to save content to your profile.
Article saved!
Access saved content from your profile page. View Saved
Join The Conversation
Create a free account today to participate in forum conversations, comment on posts and more.
Copyright ©2019 BWW Media Group