Bird
Raised Fist0
PowerShellscripting~5 mins

Scheduled scripts with Task Scheduler in PowerShell - Cheat Sheet & Quick Revision

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is Task Scheduler in Windows?
Task Scheduler is a Windows tool that lets you run scripts or programs automatically at set times or events, like a reminder alarm for your computer.
Click to reveal answer
beginner
How do you create a basic scheduled task using PowerShell?
You use the <code>Register-ScheduledTask</code> cmdlet with a trigger (when to run) and an action (what to run). For example, to run a script daily at 9 AM.
Click to reveal answer
beginner
What is a 'trigger' in Task Scheduler?
A trigger is the condition or time that starts the task, like a specific time, when the computer starts, or when a user logs in.
Click to reveal answer
intermediate
Why is it important to set the correct user account for a scheduled task?
Because the task runs with that user's permissions. If the user lacks rights, the task might fail or not access needed files.
Click to reveal answer
intermediate
How can you check if a scheduled task ran successfully using PowerShell?
You can use Get-ScheduledTask and Get-ScheduledTaskInfo to see the last run time and status of the task.
Click to reveal answer
What PowerShell cmdlet is used to create a new scheduled task?
ARegister-ScheduledTask
BNew-TaskScheduler
CStart-ScheduledTask
DInvoke-Task
Which of the following is NOT a valid trigger for a scheduled task?
AAt system startup
BWhen a file is deleted
CAt log on
DDaily at a specific time
If a scheduled task needs to run even when no user is logged in, what should you do?
ASet the task to run whether the user is logged on or not
BSet the task to run only when the user is logged on
CDisable the task
DRun the task manually
Which PowerShell cmdlet helps you see the last run time of a scheduled task?
AGet-TaskHistory
BGet-TaskStatus
CGet-ScheduledTaskInfo
DShow-ScheduledTask
What happens if the user account running the scheduled task does not have permission to access a file the script needs?
AThe task will run successfully anyway
BThe task will ask for permission
CThe task will run as administrator automatically
DThe task will fail or produce errors
Explain how to schedule a PowerShell script to run daily at 7 AM using Task Scheduler.
Think about triggers and actions in Task Scheduler.
You got /4 concepts.
    Describe why setting the correct user account and permissions is important for scheduled tasks.
    Consider what happens if permissions are missing.
    You got /4 concepts.

      Practice

      (1/5)
      1. What is the main purpose of using Task Scheduler with PowerShell scripts?
      easy
      A. To write scripts faster using a graphical interface
      B. To convert scripts into executable files
      C. To debug scripts interactively
      D. To run scripts automatically at specific times without manual start

      Solution

      1. Step 1: Understand Task Scheduler's role

        Task Scheduler is designed to run tasks automatically based on a schedule.
      2. Step 2: Identify the benefit for scripts

        Running scripts automatically saves time and ensures tasks run without forgetting.
      3. Final Answer:

        To run scripts automatically at specific times without manual start -> Option D
      4. Quick Check:

        Task Scheduler automates script running [OK]
      Hint: Task Scheduler automates script runs on schedule [OK]
      Common Mistakes:
      • Thinking Task Scheduler helps write or debug scripts
      • Confusing automation with script editing
      • Assuming it converts scripts to executables
      2. Which of the following is the correct syntax to create a scheduled task that runs a PowerShell script daily at 7 AM using schtasks?
      easy
      A. schtasks /create /tn "MyTask" /tr "powershell.exe -File C:\Scripts\task.ps1" /sc daily /st 07:00
      B. schtasks /run /tn "MyTask" /tr "powershell.exe -File C:\Scripts\task.ps1" /sc daily /st 07:00
      C. schtasks /delete /tn "MyTask" /tr "powershell.exe -File C:\Scripts\task.ps1" /sc daily /st 07:00
      D. schtasks /create /tn "MyTask" /tr "C:\Scripts\task.ps1" /sc hourly /st 07:00

      Solution

      1. Step 1: Identify the command to create a task

        The /create option is used to create a new scheduled task.
      2. Step 2: Check the task action and schedule

        The task runs PowerShell with the script file path, scheduled daily at 07:00.
      3. Final Answer:

        schtasks /create /tn "MyTask" /tr "powershell.exe -File C:\Scripts\task.ps1" /sc daily /st 07:00 -> Option A
      4. Quick Check:

        Use /create with /tn, /tr, /sc daily, /st 07:00 [OK]
      Hint: Use /create to schedule, not /run or /delete [OK]
      Common Mistakes:
      • Using /run instead of /create to schedule
      • Omitting powershell.exe in /tr argument
      • Wrong schedule type like hourly instead of daily
      3. What will be the output when running this command?
      schtasks /query /tn "BackupTask"

      Assuming the task "BackupTask" exists and is scheduled.
      medium
      A. Deletes the task named "BackupTask"
      B. Creates a new task named "BackupTask"
      C. Displays details of the scheduled task named "BackupTask"
      D. Shows an error because /query cannot be used with /tn

      Solution

      1. Step 1: Understand the /query option

        The /query option lists information about scheduled tasks.
      2. Step 2: Using /tn with /query

        Specifying /tn "BackupTask" filters the query to show only that task's details.
      3. Final Answer:

        Displays details of the scheduled task named "BackupTask" -> Option C
      4. Quick Check:

        /query with /tn shows task info [OK]
      Hint: Use /query with /tn to see specific task info [OK]
      Common Mistakes:
      • Confusing /query with /create or /delete
      • Thinking /query with /tn causes error
      • Expecting task creation or deletion output
      4. You wrote this command to schedule a script:
      schtasks /create /tn "DailyReport" /tr "powershell.exe C:\Scripts\report.ps1" /sc daily /st 09:00

      But the task does not run at 9 AM. What is the likely error?
      medium
      A. Using /sc daily instead of /sc hourly
      B. Missing the -File parameter before the script path in /tr
      C. Task name "DailyReport" is invalid
      D. Start time format 09:00 is incorrect

      Solution

      1. Step 1: Check the /tr argument syntax

        The PowerShell command should include -File before the script path to run it properly.
      2. Step 2: Understand why missing -File causes failure

        Without -File, PowerShell does not know to execute the script file, so the task runs but does nothing.
      3. Final Answer:

        Missing the -File parameter before the script path in /tr -> Option B
      4. Quick Check:

        PowerShell needs -File to run script [OK]
      Hint: Always include -File before script path in /tr [OK]
      Common Mistakes:
      • Omitting -File in PowerShell command
      • Changing schedule type unnecessarily
      • Assuming task name or time format is wrong
      5. You want to schedule a PowerShell script to run every Monday and Friday at 6 PM. Which schtasks command correctly sets this up?
      hard
      A. schtasks /create /tn "WeeklyTask" /tr "powershell.exe -File C:\Scripts\weekly.ps1" /sc weekly /d MON,FRI /st 18:00
      B. schtasks /create /tn "WeeklyTask" /tr "powershell.exe -File C:\Scripts\weekly.ps1" /sc daily /d MON,FRI /st 18:00
      C. schtasks /create /tn "WeeklyTask" /tr "powershell.exe -File C:\Scripts\weekly.ps1" /sc weekly /d 1,5 /st 18:00
      D. schtasks /create /tn "WeeklyTask" /tr "powershell.exe -File C:\Scripts\weekly.ps1" /sc monthly /d MON,FRI /st 18:00

      Solution

      1. Step 1: Choose correct schedule type for specific weekdays

        The /sc weekly option schedules tasks weekly on specified days.
      2. Step 2: Specify days and time correctly

        Use /d MON,FRI to run on Monday and Friday, and /st 18:00 for 6 PM start time.
      3. Final Answer:

        schtasks /create /tn "WeeklyTask" /tr "powershell.exe -File C:\Scripts\weekly.ps1" /sc weekly /d MON,FRI /st 18:00 -> Option A
      4. Quick Check:

        Weekly schedule with MON,FRI days and 18:00 time [OK]
      Hint: Use /sc weekly with /d MON,FRI for specific weekdays [OK]
      Common Mistakes:
      • Using /sc daily instead of weekly for specific days
      • Using numeric days instead of MON,FRI
      • Choosing monthly schedule incorrectly