Manu2287
Manu2287

Reputation: 27

Automate powershell script when system boots

I have the following powershell script:

(Get-Content C:/sample.txt -TotalCount 1) | Set-Content C:\sample.txt

I would like the above script to execute when system boot.

Can someone please advise the best option to do so? Thank you Manu

Upvotes: 0

Views: 549

Answers (2)

Manu2287
Manu2287

Reputation: 27

Best solution to solve the situation: -create a .cmd file to execute automatically your script at system boot, with following script: PowerShell -Command "Set-ExecutionPolicy Unrestricted" | powershell.exe -noexit C:\cldscripts\sample.ps1

Copy and save your .cmd file in the following path: C:\Users\youruser\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup Reboot your system and the scrip will automatically run.

Another way I found, is to use the grouop local editor: Run the gpedit.msc and enter. In the left pane tree choose windows settings under Computer configuration, double click on the feature "Scripts (Startup/Shutdown)" and add your script to run automatically at system boot or shutdown.

Best Regards

Upvotes: 0

Vladimir Bundalo
Vladimir Bundalo

Reputation: 655

you can create a scheduled task and configure it to run the script when the server boots. Every time server starts, it will start the script.

enter image description here

Upvotes: 3

Related Questions