Run PowerShell scripts on a schedule with Task Scheduler

To run a PowerShell script on a schedule, create a Task Scheduler task that starts powershell.exe with -File and the full path of your .ps1 file.

This guide covers the Task Scheduler window, Register-ScheduledTask and schtasks, running as SYSTEM, logging, four report scripts worth scheduling, and fixes for tasks that do not run.

Run PowerShell scripts on a schedule with Task Scheduler
Program/script holds powershell.exe, and Add arguments (optional) holds -File followed by the full path of the .ps1 file. (Image: Microsoft Q&A)

Run a PowerShell script on a schedule with Register-ScheduledTask

Three lines in a PowerShell window create the whole task. Replace the script path, task name and time with your own.

$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument '-NoProfile -NonInteractive -ExecutionPolicy Bypass -File "C:\Scripts\Report.ps1"'
$trigger = New-ScheduledTaskTrigger -Daily -At 3am
Register-ScheduledTask -TaskName "Daily report script" -Action $action -Trigger $trigger

New-ScheduledTaskAction sets the program Task Scheduler starts and its arguments. New-ScheduledTaskTrigger -Daily -At 3am runs it every day at 3:00 AM. Register-ScheduledTask saves the task under your account with the default Limited run level.

You should see: Daily report script appears in Task Scheduler Library with the status Ready, and Start-ScheduledTask -TaskName "Daily report script" runs it once on demand.

Test the script in a normal PowerShell window first. Task Scheduler only starts it, so a script that fails by hand fails on schedule too.

How to schedule a PowerShell script in Task Scheduler

The Create Task dialog shows every option, including the account and the arguments field. You can also open Task Scheduler from the Run box or Control Panel.

  1. Select Start, type Task Scheduler and select it under Best match.
  2. Select Action > Create Task.
  3. On the General tab, type a name and a description for the task.
  4. On the Triggers tab, select New, choose On a schedule in Begin the task, set the start time and recurrence, then select OK.
  5. On the Actions tab, select New and keep Start a program in the Action field.
  6. Type powershell.exe in Program/script.
  7. In Add arguments (optional), type -NoProfile -NonInteractive -ExecutionPolicy Bypass -File "C:\Scripts\Report.ps1".
  8. In Start in (optional), type the script folder, such as C:\Scripts, then select OK twice.

Select Run with highest privileges on the General tab when the script changes system settings or writes to protected folders.

Schedule a PowerShell script in Task Scheduler with the New Action dialog
On the Actions tab, New opens this dialog with Start a program already selected in the Action field. (Image: Microsoft Q&A)

Task Scheduler arguments for PowerShell scripts

Everything in Add arguments (optional) goes to powershell.exe, not to your script. These switches decide whether an unattended run finishes or hangs.

Switch What it does When to use it
-File "path" Runs the script. Every value after it is passed to the script as a parameter. Always, and keep it last on the line
-ExecutionPolicy Bypass Sets the execution policy for this session only. The registry setting stays unchanged. Windows clients default to Restricted, which blocks scripts
-NoProfile Skips loading the PowerShell profile. Always, so profile code cannot change the result
-NonInteractive Turns Read-Host and confirmation prompts into errors instead of a hang. Every unattended task
-WindowStyle Hidden Sets the window style. Valid values are Normal, Minimized, Maximized and Hidden. Tasks that run in your signed-in session
-Command "…" Runs a string as PowerShell code. It must be the last switch. One-line jobs without a .ps1 file

Script parameters go after the path, for example -File "C:\Scripts\Report.ps1" -Days 7. They arrive as literal strings, so $Env:windir is not expanded there.

If you installed PowerShell 7, put pwsh.exe in Program/script. Run (Get-Command pwsh).Source to get its full path.

Schedule a PowerShell script with schtasks

schtasks works from Command Prompt and from batch files, which suits deployment scripts and older tooling.

schtasks /create /tn "Daily report script" /sc daily /st 03:00 /tr "powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -File C:\Scripts\Report.ps1"

/tn names the task, /sc daily sets the schedule, /st 03:00 sets the start time in 24-hour format, and /tr holds the command, up to 262 characters. Add /ru system to run as the local System account, or /rl highest for the highest run level instead of the default LIMITED.

You should see: The task appears in Task Scheduler Library under the name you gave in /tn.

Keep the script in a folder without spaces when you use schtasks, because the whole /tr value already sits inside quotation marks.

Run a PowerShell script every 15 minutes, hourly, daily or at startup

Pick the row that matches your schedule and use either column. Both create the same kind of trigger.

Schedule you want PowerShell trigger schtasks switches
Once at a set time New-ScheduledTaskTrigger -Once -At 3am /sc once /st 03:00
Every day New-ScheduledTaskTrigger -Daily -At 3am /sc daily /st 03:00
Every 3 days New-ScheduledTaskTrigger -Daily -DaysInterval 3 -At 3am /sc daily /mo 3 /st 03:00
Every other Friday New-ScheduledTaskTrigger -Weekly -WeeksInterval 2 -DaysOfWeek Friday -At 3am /sc weekly /mo 2 /d FRI /st 03:00
Every 15 minutes New-ScheduledTaskTrigger -Once -At 9am -RepetitionInterval (New-TimeSpan -Minutes 15) -RepetitionDuration (New-TimeSpan -Hours 8) /sc minute /mo 15
Every hour, with no end date Use the schtasks switches /sc hourly
Every time Windows starts New-ScheduledTaskTrigger -AtStartup /sc onstart
When a user signs in New-ScheduledTaskTrigger -AtLogOn /sc onlogon

-RepetitionInterval and -RepetitionDuration work only with -Once, so that row repeats for eight hours from 9:00 AM. schtasks minute and hourly schedules have no end time unless you add /et or /du.

A logon-triggered task can also wait a set time after sign-in before the script starts.

Run a PowerShell script hourly with a daily trigger repeating every hour
This daily trigger repeats the task every 1 hour for a duration of Indefinitely, the dialog version of an hourly schedule. (Image: Microsoft Q&A)

Run a scheduled PowerShell script as SYSTEM with highest privileges

With UAC on, a task runs with low privileges by default. Register it from an elevated PowerShell window, because a standard window cannot register a Highest or Local System task.

  1. Open PowerShell as administrator.
  2. Build the action: $action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument '-NoProfile -NonInteractive -ExecutionPolicy Bypass -File "C:\Scripts\Cleanup.ps1"'.
  3. Build the trigger: $trigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek Sunday -At 2am.
  4. Register it: Register-ScheduledTask -TaskName "Weekly cleanup script" -Action $action -Trigger $trigger -User "NT AUTHORITY\SYSTEM" -RunLevel Highest.
  5. Run it once to test: Start-ScheduledTask -TaskName "Weekly cleanup script".

No password is needed for NT AUTHORITY\SYSTEM, LOCALSERVICE or NETWORKSERVICE. SYSTEM is highly privileged, so give it only scripts you wrote, stored where standard users cannot edit them.

To run as a normal account while signed out, register with that account and its password. Such tasks need the Log on as a batch job right, which Administrators and Backup Operators have by default.

Scheduled task settings for PowerShell scripts on laptops

By default a task does not start on battery power, which explains many missed runs on laptops. New-ScheduledTaskSettingsSet changes that and more.

New-ScheduledTaskSettingsSet switch What it changes
-AllowStartIfOnBatteries Lets the task start while the PC runs on battery
-DontStopIfGoingOnBatteries Keeps the script running when the charger is unplugged
-StartWhenAvailable Runs a missed start any time after its scheduled time has passed
-WakeToRun Wakes the computer before the task runs
-ExecutionTimeLimit (New-TimeSpan -Hours 2) Sets how long Task Scheduler allows the task to complete
-MultipleInstances IgnoreNew Ignores a new run while one is still going; Queue and Parallel are the other values
-RestartCount 3 -RestartInterval (New-TimeSpan -Minutes 60) Retries a failed task up to three times, an hour apart

Apply the settings when you register: $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable, then add -Settings $settings to Register-ScheduledTask.

Scheduled task settings for laptops on the Conditions tab Power options
Start the task only if the computer is on AC power is ticked here, which is why a laptop on battery skips the run. (Image: Microsoft Q&A)

Log scheduled PowerShell script output with Start-Transcript

A scheduled script has no console you can read. A transcript file records every command and its output instead.

  1. Create a log folder, such as C:\Scripts\Logs.
  2. Add Start-Transcript -Path "C:\Scripts\Logs\Report.txt" -Append as the first line of the script.
  3. Add Stop-Transcript as the last line.
  4. End the script with exit 0 on success, or exit 1 after a caught error, so Last Run Result reports the outcome.
  5. Run the task once, then open Report.txt and read the newest entry.

Without -Path, Start-Transcript writes to $HOME\Documents of whichever account runs the task, which is easy to miss for SYSTEM tasks.

PowerShell: Configure certificate-based authentication for Exchange Online (Azure)

Scheduled Exchange Online scripts cannot answer a sign-in prompt, and a stored password is poor security. App-only authentication uses a Microsoft Entra app and a certificate instead.

  1. Register a new application in Microsoft Entra ID with Accounts in this organizational directory only selected.
  2. Under API permissions, add Exchange.ManageAsApp from Office 365 Exchange Online, then select Grant admin consent for <Organization>.
  3. On the PC that will run the task, open PowerShell as administrator and run $mycert = New-SelfSignedCertificate -DnsName "contoso.org" -CertStoreLocation "cert:\CurrentUser\My" -NotAfter (Get-Date).AddYears(1) -KeySpec KeyExchange.
  4. Export the public key with $mycert | Export-Certificate -FilePath mycert.cer, and note $mycert.Thumbprint.
  5. On the app's Certificates & secrets page, select Upload certificate, choose mycert.cer and select Add.
  6. Assign the app a Microsoft Entra role such as Exchange Administrator or Global Reader.
  7. Start the script with Connect-ExchangeOnline -CertificateThumbPrint "<thumbprint>" -AppID "<application ID>" -Organization "contoso.onmicrosoft.com".
  8. Register the task under the same user account, because the certificate lives in that account's cert:\CurrentUser\My store.

Use your primary .onmicrosoft.com domain for -Organization. The CertificateThumbprint parameter works only on Windows. End the script with Disconnect-ExchangeOnline -Confirm:$false.

Tracking printer usage with Windows Event Viewer logs

Windows writes print activity to its PrintService event logs. A nightly script can copy the last day of events to a CSV file you open in Excel.

  1. Open PowerShell as administrator and list the print logs with Get-WinEvent -ListLog *PrintService*.
  2. If the Operational log shows a RecordCount of 0, enable it with wevtutil sl "<log name>" /e:true, using the exact name from the list.
  3. Save this line as C:\Scripts\PrintLog.ps1: Get-WinEvent -FilterHashtable @{ LogName = '*PrintService*'; StartTime = (Get-Date).AddDays(-1) } -ErrorAction SilentlyContinue | Select-Object TimeCreated, Id, Message | Export-Csv -Path C:\Scripts\Logs\PrintLog.csv -NoTypeInformation -Append.
  4. Register it with the daily trigger from the first section, pointing -File at C:\Scripts\PrintLog.ps1.
  5. Open PrintLog.csv after the first run to read each event's time, ID and message.

Wildcards work in the LogName and ProviderName keys of -FilterHashtable, so one query reads every PrintService log.

Check the software installation/removal history in Windows

Windows Installer records every MSI install and removal in the Application log. A weekly script turns those events into a running history file.

Get-WinEvent -FilterHashtable @{ LogName = 'Application'; Id = 1033, 1034; StartTime = (Get-Date).AddDays(-7) } | Select-Object TimeCreated, Id, Message | Export-Csv -Path C:\Scripts\Logs\InstallHistory.csv -NoTypeInformation -Append

Event 1033 means an installation completed and 1034 means a removal completed. Each message carries the product name, version, language, status and manufacturer. The query reads the last seven days.

You should see: InstallHistory.csv gains one row per install or removal, with the product name in the Message column.

Save the line as a .ps1 file and schedule it with New-ScheduledTaskTrigger -Weekly -DaysOfWeek Monday -At 8am. Add event 11707 (installation completed successfully) and 11708 (installation failed) for success and failure detail.

These events come from Windows Installer, so apps that use other installers may not appear.

Check Windows 11 hardware readiness with PowerShell script

Windows 11 needs TPM 2.0, UEFI firmware that supports Secure Boot, 4 GB of memory and 64 GB of storage. This script logs those checks on every run, so a scheduled copy tracks a fleet over time.

$tpm = Get-Tpm
$cs = Get-CimInstance -ClassName Win32_ComputerSystem
$disk = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DeviceID='C:'"
[pscustomobject]@{
  Date       = Get-Date
  TpmPresent = $tpm.TpmPresent
  TpmReady   = $tpm.TpmReady
  SecureBoot = Confirm-SecureBootUEFI
  MemoryGB   = [math]::Round($cs.TotalPhysicalMemory / 1GB, 1)
  DiskGB     = [math]::Round($disk.Size / 1GB)
} | Export-Csv -Path C:\Scripts\Logs\Win11Readiness.csv -NoTypeInformation -Append

Get-Tpm reports whether a TPM is present and ready. Confirm-SecureBootUEFI returns True when Secure Boot is on and False when it is supported but off. Win32_ComputerSystem gives memory in bytes and Win32_LogicalDisk gives the C: drive size.

You should see: Win11Readiness.csv gains a row per run. TpmReady and SecureBoot both True, at least 4 GB of memory and at least 64 GB of disk meet those four requirements.

Confirm-SecureBootUEFI needs an elevated session and reports Cmdlet not supported on this platform on BIOS PCs, so register this task with -RunLevel Highest.

The script does not read the TPM version or check the processor list, so confirm TPM 2.0 and a compatible 64-bit processor separately.

How to see if a scheduled PowerShell script ran

  1. In Task Scheduler, select Task Scheduler Library and find your task.
  2. Read the Last Run Result column. It shows the exit code the script returned, and 0x0 means exit code 0.
  3. Select the task and open the History tab to see whether it triggered and completed.
  4. In PowerShell, run Get-ScheduledTaskInfo -TaskName "Daily report script" for the last run-time information.
  5. Open the transcript or CSV file the script writes and check that the newest entry matches the last run time.

A task should sit in Ready status between runs. One that stays in Running for a long time is waiting on the script.

See if a scheduled PowerShell script ran in the Task Scheduler Library list
A task in Ready status waits for its next trigger; the Last Run Time column shows when it last started. (Image: Microsoft Q&A)

Task Scheduler Last Run Result codes for PowerShell scripts

Last Run Result Meaning What to do
0x0 The script exited with code 0 Nothing; the run succeeded
0x1 PowerShell exited with 1, usually a script-terminating error Run the same command line by hand and read the error
Another small number The script ended with exit and that number Look up the exit code in your script
0x41300 The task is ready to run at its next scheduled time Wait for the trigger or start it by hand
0x41301 The task is currently running Check whether the script waits for input
0x41303 The task has not yet run Confirm the trigger time is in the future
0x41306 The last run was terminated by the user Run it again
0x8004131F An instance of this task is already running Set -MultipleInstances or lengthen the interval

Disable or delete a scheduled PowerShell task

  1. To keep a copy, right-click the task in Task Scheduler Library and export it to an .xml file.
  2. To pause it without deleting, run Disable-ScheduledTask -TaskName "Daily report script".
  3. To remove it, run Unregister-ScheduledTask -TaskName "Daily report script" -Confirm:$false.

Deleting the task leaves the .ps1 file and its logs in place.

PowerShell script not running in Task Scheduler

Last Run Result shows 0x1

PowerShell hit a script-terminating error, or the script returned 1 itself.

  1. Copy the Program/script and Add arguments values into Command Prompt and run them together.
  2. Read the error PowerShell prints and fix the line it names.
  3. Add Start-Transcript to the script so the next scheduled run leaves a log.

The task completes, but the script does nothing

The script uses relative paths or runs under an account that lacks access.

  1. Replace relative paths in the script with full paths, or fill in Start in (optional).
  2. Change Security options to Run only when user is logged on and run the task to test the security context.
  3. Test with a simplified script to tell a script problem from an account problem.

Task stays in Running status

The script waits for input or never exits.

  1. Find powershell.exe in Task Manager to confirm the process is still alive.
  2. Add -NonInteractive so prompts fail instead of waiting.
  3. Set an execution time limit with New-ScheduledTaskSettingsSet -ExecutionTimeLimit (New-TimeSpan -Hours 2).

Running scripts is disabled on this system

Windows clients default to the Restricted execution policy, or Group Policy sets one.

  1. Add -ExecutionPolicy Bypass before -File in the task arguments.
  2. Run Get-ExecutionPolicy -List. A MachinePolicy or UserPolicy value comes from Group Policy and overrides the switch.
  3. Unblock a script you downloaded with Unblock-File -Path C:\Scripts\Report.ps1.

Access denied when creating or running the task

The account lacks admin rights or the batch logon right.

  1. Right-click Task Scheduler and select Run as administrator.
  2. Open the task's Properties, go to the General tab and select Run with highest privileges.
  3. In gpedit.msc, open Computer Configuration > Windows Settings > Security Settings > Local Policies > User Rights Assignment and confirm the account has Log on as a batch job.

Task does not start at the scheduled time

The trigger time passed, or a condition such as battery power blocked it.

  1. Set the trigger start time a few minutes in the future and save the task again.
  2. Register the task with -AllowStartIfOnBatteries and -StartWhenAvailable on laptops.
  3. Read Event Viewer > Applications and Services Logs > Microsoft > Windows > TaskScheduler > Operational for the reason.

The interactive running scripts is disabled error has the same execution policy cause.

Scheduled PowerShell script FAQ

What do I put in Program/script to run a PowerShell script?

Put powershell.exe in Program/script, or pwsh.exe for PowerShell 7. Put -NoProfile -ExecutionPolicy Bypass -File followed by the full script path in Add arguments (optional). The script path goes after -File, and any script parameters follow it.

Do I need -ExecutionPolicy Bypass in a scheduled task?

Usually yes on Windows 10 and 11, because Windows clients default to the Restricted policy. Bypass applies only to that PowerShell session and leaves the registry setting alone. It cannot override an execution policy that Group Policy sets.

Can a scheduled PowerShell script run when no one is signed in?

Yes. Register the task as NT AUTHORITY\SYSTEM, which needs no password, or under a user account with its password stored. Password-based tasks need the Log on as a batch job right, which Administrators and Backup Operators have by default.

How do I run a PowerShell script every 5 minutes?

Run schtasks /create /sc minute /mo 5 /tn "My script" /tr followed by the powershell.exe command line. The minute schedule accepts 1 to 1439 minutes and repeats with no end time unless you add /et or /du.

How do I hide the PowerShell window in a scheduled task?

Add -WindowStyle Hidden to the arguments, before -File. The switch sets the window style of the session, and its valid values are Normal, Minimized, Maximized and Hidden. Add -NonInteractive too, so a prompt the hidden window cannot show fails instead of waiting.

How do I pass parameters to a scheduled PowerShell script?

Type them after the script path in Add arguments, for example -File "C:\Scripts\Report.ps1" -Days 7. PowerShell passes them to the script as literal strings. Array parameters do not work through -File.

Does Task Scheduler work with PowerShell 7?

Yes. Use pwsh.exe instead of powershell.exe in Program/script or in New-ScheduledTaskAction -Execute. Run (Get-Command pwsh).Source to get the full path of pwsh.exe on your PC.

Where does Task Scheduler log why a task failed?

Task Scheduler writes to Event Viewer under Applications and Services Logs > Microsoft > Windows > TaskScheduler > Operational. The task's History tab shows the same events for one task, and Last Run Result shows the script's exit code.

Philip Celasco

Philip is a Texas-based technology writer and IT administrator at Techdows.com with more than 10 years of experience creating practical content for everyday users and professionals. He specializes in web browsers, particularly Chromium-based platforms such as Google Chrome, Microsoft Edge, Brave, and Opera. Through his work as an IT administrator, Philip has hands-on experience managing devices, configuring browser policies, troubleshooting software and network issues, and helping people resolve problems that affect productivity and security. His articles are based on practical testing and real-world technical experience. He covers browser settings, extensions, performance problems, privacy controls, security features, and Windows troubleshooting. Outside work, Philip enjoys the quieter side of life in Texas and stepping away from the screen when he can. He has two kids, two cats and loves to play golf with his mother during the weekends.

Leave a Reply

Your email address will not be published. Required fields are marked *