views:

407

answers:

1

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

+2  A: 

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.

Joey
I now, but how do I run the powershell in the background?
magol
@magol - How much more "background" do you need to get? The Windows task scheduler is how you would run a "background" task, and in this case, the task would be to start PowerShell and run the specified script.
Steven Murawski
Well, to be fair, the initial answer wouldn't have resulted in a background process if the current user is an administrator and doesn't change the default settings for the task. However, explicitly letting the task run regardless of the logged-on user fixes that. Hm. My test script ran 181 times so far. I should turn that task off again :-)
Joey
magol