Link to home
Start Free TrialLog in
Avatar of K B
K BFlag for United States of America

asked on

Powershell script that runs at first boot only

I would like a Powershell script to run at initial boot only please. - as an administrator.
Once, it runs successfully, I would like some sort of flag incremented so that it will not run again.

This is not Domain Joined, so GPOs are not in the picture.

Thank you!
Avatar of Qlemo
Qlemo
Flag of Germany image

Most people create a flag file somewhere, or create a registry entry, to show the script has been run. The script then only needs to check for existence to terminate execution. That part is not difficult at all.

How do you think you can get the script running on a boot in the first place?
Avatar of K B

ASKER

thank you for your reply Qlemo!

That makes sense.  So how would I fire off the script at boot (in your opinion).
Avatar of K B

ASKER

I am realizing that I would like this to run before anyone logs in.  Is that possible?
Avatar of oBdA
oBdA

That can be done with a scheduled task. Pick "Create a Basic Task" from the menu, set it to start "When the computer starts".
As Program/Script, use "Powershell.exe", as arguments (obviously adjusting the path inside the single quotes)
-ExecutionPolicy Bypass -Command "& 'C:\Wherever\script.ps1'"

Open in new window

In the "Finish" dialog, check "Open the Properties dialog ...", click "Finish", then set the user and password (you can use SYSTEM as well, no password), change the radio button to "Run whether user is logged on or not" (if not using SYSTEM), and check the box "Run with highest privileges".
If someone's fast with the logon, he might make it before it runs, but unless he's using the same account you used for the task, he won't see anything, so the success depends on what it is you want to achieve with the script.
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Instead of the reg key we could remove or disable the scheduled task after execution, which I would prefer.
Avatar of K B

ASKER

Perfect!!