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

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

    If you do not want to worry about execution policy, you can use the following and put into a batch script. I use this a lot when having techs at sites run my scripts since half the time they say script didnt work but really it's cause execution policy was undefined our restricted. This will run script even if execution policy would normally block a script to run.
    If you want it to run at startup. Then you can place in either shell:startup for a single user or shell:common startup for all users who log into the PC.

    cmd.exe /c Powershell.exe -ExecutionPolicy ByPass -File "c:\path\to\script.ps1"

    Obviously, making a GPO is your best method if you have a domain and place in Scripts (Startup/Shutdown); under either Computer or User Configurations\Windows Settings\Scripts (Startup/Shutdown). If you go that way make a directory called Startup or something under **

    \\yourdomain.com\netlogon\

    and put it there to reference in the GPO. This way you know the DC has rights to execute it. When you browse for the script on the DC you will find it under

    C:\Windows\SYSVOL\domain\scripts\Startup\

    since this is the local path of netlogon.

提交回复
热议问题