How to Run a PowerShell Script at Startup in Windows

You want a script to map drives or log a health check every time Windows starts, without anyone remembering to run it.

Quick answer: to run a PowerShell script on startup, register a scheduled task with a logon trigger that starts powershell.exe with your script:

$action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-ExecutionPolicy Bypass -File "C:\Scripts\Startup.ps1"'
$trigger = New-ScheduledTaskTrigger -AtLogOn -User "$env:USERDOMAIN\$env:USERNAME"
Register-ScheduledTask -TaskName 'Startup Script' -Action $action -Trigger $trigger

In this tutorial, we’ll run a PowerShell script on startup four ways: a scheduled task, the Startup folder, the Run registry key and Group Policy, tested on a standard account.

What You Need Before You Start

Windows PowerShell 5.1 or PowerShell 7 works. Both load the same ScheduledTasks module (Function 1.0.0.0), PowerShell 7 with no compatibility layer. Here’s how to check your PowerShell version.

Machine-wide methods need a member of the local Administrators group in a Run as administrator window.

Step 1: Create the Script You Want to Run at Startup

Our demo script adds one timestamped line to a log file, like writing to a log file in PowerShell. Run it by hand once first:

New-Item -Path C:\psfaqs\Scripts, C:\psfaqs\Logs -ItemType Directory -Force | Out-Null
$body = @'
$eastern = [TimeZoneInfo]::FindSystemTimeZoneById('Eastern Standard Time')
$now = [TimeZoneInfo]::ConvertTimeFromUtc([DateTime]::UtcNow, $eastern)
$line = '{0:yyyy-MM-dd HH:mm} ET  Startup check ran in PowerShell {1}' -f $now, $PSVersionTable.PSVersion
Add-Content -Path C:\psfaqs\Logs\startup-log.txt -Value $line
'@
Set-Content -Path C:\psfaqs\Scripts\Write-StartupLog.ps1 -Value $body

& C:\psfaqs\Scripts\Write-StartupLog.ps1
Get-Content -Path C:\psfaqs\Logs\startup-log.txt -Tail 1

Output:

2026-10-21 00:06 ET  Startup check ran in PowerShell 7.6.7

The output above is from PowerShell 7. In 5.1, the line ends with the 5.1 version number.

Step 2: Run the Script at Logon With a Scheduled Task

Task Scheduler is the most reliable option. -AtLogOn -User runs the task each time you sign in:

$me = "$env:USERDOMAIN\$env:USERNAME"
$arguments = '-NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden',
             '-File "C:\psfaqs\Scripts\Write-StartupLog.ps1"' -join ' '
$action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument $arguments
$trigger = New-ScheduledTaskTrigger -AtLogOn -User $me
Register-ScheduledTask -TaskName 'PSFAQs Startup Log' -Action $action -Trigger $trigger -Force |
    Format-Table TaskName, State -AutoSize

Output:

TaskName           State
--------           -----
PSFAQs Startup Log Ready

It runs in your own session, not elevated, so no admin rights are needed. To review it, see listing scheduled tasks with PowerShell.

Step 3: Test the Task Without Restarting

Start-ScheduledTask runs the task right away, and Get-ScheduledTaskInfo reports the result:

Start-ScheduledTask -TaskName 'PSFAQs Startup Log'
Start-Sleep -Seconds 6
(Get-ScheduledTaskInfo -TaskName 'PSFAQs Startup Log').LastTaskResult
Get-Content -Path C:\psfaqs\Logs\startup-log.txt -Tail 1

Output:

0
2026-10-21 00:07 ET  Startup check ran in PowerShell 5.1.26100.9444