Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a powershell script that I want to start when Windows 7 starts how can I do that?

share|improve this question
    
Have to start before user login? –  lg. Feb 17 '11 at 8:32
    
No, it can starts after a user login –  xdevel2000 Feb 17 '11 at 8:51

3 Answers 3

If you run this command at startup, you should be fine:

powershell.exe -noexit c:\scripts\MyAwesomeScript.ps1

More info on this subject can be found here: http://technet.microsoft.com/en-us/library/ee176949.aspx

share|improve this answer
    
I need to have a file that contain the code and auto-execute after login...like a .bat I presume... –  xdevel2000 Feb 17 '11 at 13:08
    
You could put this in a .bat and make it run that way, but I'm pretty sure you can drop this command in a Group Policy Scheduled Task. –  Bart De Vos Feb 17 '11 at 18:04

Goto Start -> Run -> taskschd.msc. Create a basic task and set the trigger to "When the computer starts". Select "%windir%\System32\WindowsPowerShell\v1.0\powershell.exe" for your program name and set the full path to your powershell script as it's argument. Note that this will only run when a user logs in to the machine.

If instead you need this script to run without requiring a user to login, then goto Start -> Run -> Gpedit.msc. Under computer Configuration -> Windows Settings -> Scripts, double click on the "Start Up" icon to edit it's properties. Click on add and then the "Script Name" to be "%windir%\System32\WindowsPowerShell\v1.0\powershell.exe" and your script parameters to be the path to your powershell script. Hope this helps

share|improve this answer

Add a link to your powershell script into StartUp folder.

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.