Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a powershell script in the background once per minute

I want a powershell script to be run once per minute in the background. No window may appear. How do I do it?

like image 396
magol Avatar asked Jan 15 '10 12:01

magol


People also ask

How do I run a PowerShell script every 15 minutes?

The only way to ensure it runs and stays running is to use Task Scheduler. Create the script in Powershell and then run the script every 15 minutes via Task Scheduler.

Does PowerShell script run in background?

The Start-Job cmdlet starts a PowerShell background job on the local computer. A PowerShell background job runs a command without interacting with the current session. When you start a background job, a job object returns immediately, even if the job takes an extended time to finish.


2 Answers

Use the Windows Task Scheduler and run your script like this:

powershell -File myScript.ps1 -WindowStyle Hidden 

Furthermore create the script that it runs under a specific user account and not only when that user is logged on. Otherwise you'll see a console window.

like image 182
Joey Avatar answered Sep 29 '22 12:09

Joey


Schedule your task to be run as System. The command below will schedule a script to be run in the background without showing powershell console window:

schtasks /create /tn myTask /tr "powershell -NoLogo -WindowStyle hidden -file myScript.ps1" /sc minute /mo 1 /ru System

/ru switch lets you change the user context in which the scheduled task will be executed.

like image 37
xemlock Avatar answered Sep 29 '22 11:09

xemlock