Bird
Raised Fist0
PowerShellscripting~20 mins

Scheduled task management in PowerShell - Practice Problems & Coding Challenges

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
Challenge - 5 Problems
🎖️
Scheduled Task Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this PowerShell command?
Consider this command that lists scheduled tasks with a specific name filter. What output will it produce?
PowerShell
Get-ScheduledTask -TaskName "Backup*" | Select-Object -ExpandProperty TaskName
A["BackupDaily", "BackupWeekly"]
BError: Get-ScheduledTask : The term 'Get-ScheduledTask' is not recognized
CTaskName : BackupDaily\nTaskName : BackupWeekly
DBackupDaily\nBackupWeekly
Attempts:
2 left
💡 Hint
Think about how Select-Object -ExpandProperty outputs values in PowerShell.
📝 Syntax
intermediate
2:00remaining
Which option correctly creates a scheduled task to run Notepad daily at 9 AM?
Select the PowerShell command that correctly creates a scheduled task named 'OpenNotepad' to run Notepad.exe every day at 9 AM.
ANew-ScheduledTask -TaskName "OpenNotepad" -Trigger (New-ScheduledTaskTrigger -Daily -At 9am) -Action (New-ScheduledTaskAction -Execute "notepad.exe")
BRegister-ScheduledTask -TaskName "OpenNotepad" -Trigger (New-ScheduledTaskTrigger -Daily -At 9am) -Action (New-ScheduledTaskAction -Execute "notepad.exe")
CRegister-ScheduledTask -Name "OpenNotepad" -Trigger (New-ScheduledTaskTrigger -Daily -At 9am) -Action (New-ScheduledTaskAction -Execute "notepad.exe")
DRegister-ScheduledTask -TaskName "OpenNotepad" -Trigger (New-ScheduledTaskTrigger -Daily -At "09:00") -Action (New-ScheduledTaskAction -Execute "notepad.exe")
Attempts:
2 left
💡 Hint
Check the parameter names and formats for Register-ScheduledTask and New-ScheduledTaskTrigger.
🔧 Debug
advanced
2:00remaining
Why does this scheduled task creation script fail?
This script is intended to create a scheduled task that runs a script daily at 7 PM. Why does it fail?
PowerShell
Register-ScheduledTask -TaskName "RunScript" -Trigger (New-ScheduledTaskTrigger -Daily -At "19:00") -Action (New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-File C:\Scripts\daily.ps1")
AThe -At parameter requires time in quotes when containing ':'; it should be -At "19:00".
BThe -Argument parameter must be an array, not a string.
CThe path in -Argument must be escaped with double backslashes.
DThe script fails because Register-ScheduledTask requires -User and -Password parameters.
Attempts:
2 left
💡 Hint
Check the format expected by the -At parameter in New-ScheduledTaskTrigger.
🚀 Application
advanced
2:00remaining
How to disable a scheduled task using PowerShell?
You want to disable a scheduled task named 'DataSync'. Which command will do this correctly?
ADisable-ScheduledTask -TaskName "DataSync"
BSet-ScheduledTask -TaskName "DataSync" -Enabled $false
CStop-ScheduledTask -TaskName "DataSync"
DRemove-ScheduledTask -TaskName "DataSync"
Attempts:
2 left
💡 Hint
Disabling a task means it won't run but still exists.
🧠 Conceptual
expert
3:00remaining
What is the effect of this PowerShell snippet on scheduled tasks?
What does this script do? $tasks = Get-ScheduledTask | Where-Object { $_.State -eq 'Ready' -and $_.TaskName -like '*Backup*' } foreach ($task in $tasks) { Disable-ScheduledTask -TaskName $task.TaskName }
AEnables all scheduled tasks with 'Backup' in their name that are currently disabled.
BDeletes all scheduled tasks with 'Backup' in their name that are currently ready to run.
CDisables all scheduled tasks with 'Backup' in their name that are currently ready to run.
DStarts all scheduled tasks with 'Backup' in their name that are currently ready.
Attempts:
2 left
💡 Hint
Look at the filtering and the command inside the loop.

Practice

(1/5)
1. What is the main purpose of a scheduled task in PowerShell?
easy
A. To monitor system performance continuously
B. To manually execute scripts only when needed
C. To run scripts or programs automatically at specific times
D. To edit files in the system

Solution

  1. Step 1: Understand scheduled task purpose

    Scheduled tasks are designed to automate running scripts or programs without manual intervention.
  2. Step 2: Compare options

    Only To run scripts or programs automatically at specific times describes automatic execution at set times, which matches scheduled tasks.
  3. Final Answer:

    To run scripts or programs automatically at specific times -> Option C
  4. Quick Check:

    Scheduled tasks automate running scripts [OK]
Hint: Scheduled tasks run automatically on a schedule [OK]
Common Mistakes:
  • Confusing scheduled tasks with manual script runs
  • Thinking scheduled tasks monitor system performance
  • Assuming scheduled tasks edit files automatically
2. Which PowerShell cmdlet is used to create a new scheduled task trigger?
easy
A. New-ScheduledTaskTrigger
B. New-ScheduledTaskAction
C. Register-ScheduledTask
D. Get-ScheduledTask

Solution

  1. Step 1: Identify cmdlet for trigger creation

    The cmdlet New-ScheduledTaskTrigger is specifically used to define when a scheduled task should run.
  2. Step 2: Differentiate from other cmdlets

    New-ScheduledTaskAction defines what runs, Register-ScheduledTask registers the task, and Get-ScheduledTask retrieves tasks.
  3. Final Answer:

    New-ScheduledTaskTrigger -> Option A
  4. Quick Check:

    Trigger creation cmdlet = New-ScheduledTaskTrigger [OK]
Hint: Trigger means when task runs, use New-ScheduledTaskTrigger [OK]
Common Mistakes:
  • Using New-ScheduledTaskAction instead of trigger cmdlet
  • Confusing Register-ScheduledTask with trigger creation
  • Trying to get tasks instead of creating triggers
3. What will the following PowerShell command output?
Get-ScheduledTask -TaskName 'MyTask' | Select-Object -ExpandProperty State
medium
A. The current state of the scheduled task named 'MyTask'
B. The list of all scheduled tasks on the system
C. The actions defined in the scheduled task
D. An error because Select-Object cannot expand properties

Solution

  1. Step 1: Understand Get-ScheduledTask output

    Get-ScheduledTask with -TaskName returns the task object for 'MyTask'.
  2. Step 2: Use Select-Object -ExpandProperty State

    This extracts the 'State' property value, showing the task's current status (e.g., Ready, Running).
  3. Final Answer:

    The current state of the scheduled task named 'MyTask' -> Option A
  4. Quick Check:

    Expanding State property shows task status [OK]
Hint: Select-Object -ExpandProperty extracts property value directly [OK]
Common Mistakes:
  • Thinking it lists all tasks instead of one
  • Confusing State with actions or triggers
  • Assuming Select-Object cannot expand properties
4. You run this command but get an error:
Register-ScheduledTask -TaskName 'Backup' -Trigger $trigger -Action $action

What is the most likely cause?
medium
A. TaskName 'Backup' is already in use
B. PowerShell does not support Register-ScheduledTask
C. Register-ScheduledTask requires -User parameter
D. Variables $trigger or $action are not defined or invalid

Solution

  1. Step 1: Check variables used in command

    $trigger and $action must be valid scheduled task trigger and action objects before registering.
  2. Step 2: Understand error cause

    If these variables are missing or invalid, Register-ScheduledTask fails with an error.
  3. Final Answer:

    Variables $trigger or $action are not defined or invalid -> Option D
  4. Quick Check:

    Undefined variables cause Register-ScheduledTask error [OK]
Hint: Ensure $trigger and $action are created before registering task [OK]
Common Mistakes:
  • Assuming task name conflict causes error
  • Thinking -User parameter is always required
  • Believing Register-ScheduledTask is unsupported in PowerShell
5. You want to create a scheduled task that runs a script every day at 6 AM. Which sequence of commands correctly sets this up?
hard
A. $action = New-ScheduledTaskTrigger -Daily -At 6am; $trigger = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-File C:\Scripts\daily.ps1'; Register-ScheduledTask -TaskName 'DailyScript' -Trigger $trigger -Action $action
B. $trigger = New-ScheduledTaskTrigger -Daily -At 6am; $action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-File C:\Scripts\daily.ps1'; Register-ScheduledTask -TaskName 'DailyScript' -Trigger $trigger -Action $action
C. Register-ScheduledTask -TaskName 'DailyScript' -Trigger 'Daily' -Action 'powershell.exe -File C:\Scripts\daily.ps1'
D. $trigger = New-ScheduledTaskAction -Daily -At 6am; $action = New-ScheduledTaskTrigger -Execute 'powershell.exe' -Argument '-File C:\Scripts\daily.ps1'; Register-ScheduledTask -TaskName 'DailyScript' -Trigger $trigger -Action $action

Solution

  1. Step 1: Create correct trigger and action objects

    New-ScheduledTaskTrigger defines when (daily at 6am), New-ScheduledTaskAction defines what (powershell.exe running script).
  2. Step 2: Register the scheduled task with proper parameters

    Use Register-ScheduledTask with -TaskName, -Trigger, and -Action using the created objects.
  3. Final Answer:

    Correct sequence is creating trigger then action, then registering task -> Option B
  4. Quick Check:

    Trigger = when, Action = what, Register with both [OK]
Hint: Trigger sets time, Action sets program, Register combines both [OK]
Common Mistakes:
  • Swapping trigger and action cmdlets
  • Passing strings instead of objects to Register-ScheduledTask
  • Omitting required parameters in Register-ScheduledTask