If you want to run a PowerShell script before anyone signs on, you have a couple of options.
To run your script infrequently, such as once per day, use the Windows Task Scheduler. A basic task should be adequate for your needs.
-
Download and install AlwaysUp, if necessary.
-
Start AlwaysUp.
-
Select Application > Advisor to open the Application Advisor:
-
Click Next to get started:
-
Choose PowerShell from the list of applications and click Next:
-
Here, tell AlwaysUp what script you want to run. Enter the full path to your .ps1 file:
-
On this screen, you'll be prompted to enter the user name and password of a Windows account where you know your PowerShell script works:
Click Next to move on.
-
AlwaysUp is done gathering information. Click Next to continue:
-
The Add Application window contains all the recommended settings for running your PowerShell script 24x7 after your computer boots.
Click Save to install your new PowerShell service:
-
In a couple of seconds, a new entry named for your PowerShell script will show up in the AlwaysUp window.
The state will be "Stopped" because the service isn't running yet:
-
In this default setup, AlwaysUp will automatically restart your PowerShell script immediately after it stops.
The effect is to run your script continuously, without any pauses.
If that's not what you want — say you want to run your script every few minutes instead — you should make the following changes:
Edit your PowerShell script in AlwaysUp. You can either double-click the row or select Edit from the Application menu.
Switch to the Restart tab.
Adjust the controls to reflect how often AlwaysUp should run your script. For example, we chose every hour, on the hour:
Activate the Minimize event logging option, to reduce chatter as your script starts and stops frequently.
Check the Don't panic box, especially if your script can do its work and exit very quickly.
Click Save to record your changes.
-
Finally, to launch your PowerShell script as a service, choose Application > Start.
The entry will transition to "Running" and your script will be active in the background
(in Session 0):
If you decided to pause between runs of your script (in step 11), you may occasionally see the service waiting too:
-
That's it! Next time your computer boots, your PowerShell script will start immediately, before anyone logs on. And AlwaysUp will ensure that it runs whenever it should.
We encourage you to edit the entry in AlwaysUp and check out the many other settings that may be appropriate for your environment.
For example, you can: