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

前端 未结 15 1176
-上瘾入骨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:56

    A relatively short path to specifying a Powershell script to execute at startup in Windows could be:

    1. Click the Windows-button (Windows-button + r)
    2. Enter this:

    shell:startup

    1. Create a new shortcut by rightclick and in context menu choose menu item: New=>Shortcut

    2. Create a shortcut to your script, e.g:

    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -Command "C:\Users\someuser\Documents\WindowsPowerShell\Scripts\somesscript.ps1"

    Note the use of -NoProfile In case you put a lot of initializing in your $profile file, it is inefficient to load this up to just run a Powershell script. The -NoProfile will skip loading your profile file and is smart to specify, if it is not necessary to run it before the Powershell script is to be executed.

    Here you see such a shortcut created (.lnk file with a Powershell icon with shortcut glyph):

提交回复
热议问题