How do I run a PowerShell script when the computer starts?

前端 未结 15 1154
-上瘾入骨i
-上瘾入骨i 2020-11-30 19:24

I have a PowerShell script that monitors an image folder. I need to find a way to automatically run this script after the computer starts.

I already tried the follow

15条回答
  •  独厮守ぢ
    2020-11-30 19:34

    You could create a Scheduler Task that runs automatically on the start, even when the user is not logged in:

    schtasks /create /tn "FileMonitor" /sc onstart /delay 0000:30 /rl highest /ru system /tr "powershell.exe -file C:\Doc\Files\FileMonitor.ps1"
    

    Run this command once from a PowerShell as Admin and it will create a schedule task for you. You can list the task like this:

    schtasks /Query /TN "FileMonitor" /V /FO List
    

    or delete it

    schtasks /Delete /TN "FileMonitor"
    

提交回复
热议问题