I have a PowerShell script that monitors an image folder. I need to find a way to auto run this script after the computer starts.
I already tried the following methods, but I couldn't get it working.
14.2k1919 gold badges8888 silver badges115115 bronze badges
qinking126
Outlook For Vistaqinking126
4,2121616 gold badges6060 silver badges108108 bronze badges
10 Answers
I finally got my PowerShell script to run automatically on every startup. You will need to create two files: the first is the Powershell script (e.g.
script.ps1 ) and the second is a .cmd file that will contain commands that will run on the command prompt (e.g. startup.cmd ).
The second file is what needs to be executed when the computer starts up, and simply copy-pasting the .ps1 to the startup folder won't work, because that doesn't actually execute the script - it only opens the file with Notepad. You need to execute the .cmd which itself will execute the .ps1 using PowerShell. Ok, enough babbling and on to the steps:
C:Users<user_name>Desktopscript.ps1
C:Users<user_name>AppDataRoamingMicrosoftWindowsStart MenuProgramsStartupstartup.cmd
Doing this will execute the cmd file every time on startup. Here is a link of how to create a .cmd file if you need help.
This will do two things:
This code is specifically for PowerShell v1.0. If you're running PowerShell v2.0 it might be a little different. In any case, check this source for the .cmd code.
Now that you have your .ps1 and .cmd files in their respective paths and with the script for each, you are all set.
alex
2,59166 gold badges3333 silver badges6767 bronze badges
Helpy-HelpertonHelpy-Helperton
You could set it up as a Scheduled Task, and set the Task Trigger for 'At Startup'
mjolinormjolinor
51.7k33 gold badges7474 silver badges103103 bronze badges
What I do is create a shortcut that I place in shell:startup.
The shortcut has the following:
Target:
C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -Command 'C:scriptsscript.ps1'
(replacing scriptsscripts.ps1 with what you need)
Start In:
C:scripts
(replacing scripts with folder which has your script)
haboutnnahhaboutnnah
Copy ps1 into this folder, and create it if necessary. It will run at every start-up (before user logon occurs).
Also it can be done through GPEDIT.msc if available on your OS build (lower level OS maybe not).
Peter Mortensen
14.2k1919 gold badges8888 silver badges115115 bronze badges
Knuckle-DraggerKnuckle-Dragger
4,68122 gold badges1717 silver badges3535 bronze badges
I have a script that starts a file system watcher as well, but once the script window is closed the watcher dies. It will run all day if I start it from a powershell window and leave it open, but the minute I close it the script stops doing what it is supposed to.
You need to start the script and have it keep powershell open. I tried numerous ways to do this, but the one that actually worked was from http://www.methos-it.com/blogs/keep-your-powershell-script-open-when-executed
Pasting that to the top of the script is what made it work.
I start the script from command line with powershell.exe -noexit -command '& pathtoscript.ps1'
10.1k1313 gold badges3030 silver badges6262 bronze badges
DanDan
A relatively short path to specifying a Powershell script to execute at startup in Windows could be:
shell:startup
C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -NoProfile -Command 'C:UserssomeuserDocumentsWindowsPowerShellScriptssomesscript.ps1'
Note the use of -NoProfile In case you put a lot of initializing in your $profile file, it is inefficient to load this up to just run a Powershell script. The -NoProfile will skip loading your profile file and is smart to specify, if it is not necessary to run it before the Powershell script is to be executed.
Here you see such a shortcut created (.lnk file with a Powershell icon with shortcut glyph):
Tore AurstadTore Aurstad
Start Non-interactive Outlook 2010 Command Line Select 2
This worked for me. Created a Scheduled task with below details:Trigger : At startup
Actions:Program/script : powershell.exeArguments : -file
Justin DJustin D
You can see scripts and more scheduled for startup inside Task Manager in the Startup tab. Here is how to add a new item to the scheduled startup items.
First, open up explorer to shell:startup location via start-button => run:
explorer shell:startup
Right click in that folder and in the context menu select a new shortcut. Enter the following:
C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -NoProfile -Command 'C:myfoldersomescript.ps1'
This will startup a Powershell script without starting up your $profile scripts for faster execution. This will make sure that the powershell script is started up.
The shell:startup folder is in:
$env:APPDATAMicrosoftWindows
Start Non-interactive Outlook 2010 Command Line Select File
And then into the folder:
Start MenuProgramsStartup
As usual, Microsoft makes things a bit cumbersome for us when a path contains spaces, so you have to put quotes around the full path or just hit tab inside Powershell to autocomplete in this case.
Tore AurstadTore Aurstad
You could create a Scheduler Task that runs automatically on the start, even when the user is not logged in:
Run this command once from a PowerShell as Admin and it will create a schedule task for you. You can list the task like this:
or delete it
hirschnasehirschnase
Be sure, whenever you want PowerShell to run automatically / in the background / non-interactive, it’s a good idea to specify the parameters
-ExecutionPolicy Bypass to PowerShell.exe
PowerShell.exe -ExecutionPolicy Bypass
bcdadybcdady
Not the answer you're looking for? Browse other questions tagged powershell or ask your own question.You can specify whether Microsoft Outlook should prompt you to choose between working online or offline with your Microsoft Exchange Server account, or always start in online mode when your Exchange mailbox is available.
Note: A Microsoft Exchange Server account is required.
Tell me more about these two options Automatically detect connect state Outlook starts in offline mode if a connection the your Exchange server is not available. Manually control connection state When Outlook starts, you are prompted to choose whether to work online or offline. This option provides you with the ability to work offline, even if a connection to Exchange is available.
Note: If you have not set up Outlook to work offline and are not using Cached Exchange Mode, none of your Outlook data is available when there is not a connection to Exchange.
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |