I want a powershell script to be run once per minute in the background. No window may appear. How do I do it?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With