Schedule powershell script

Sometimes it’s necessary to run powershell scripts on regular time. Just create a normal Windows scheduled job and insert the command below

Powershell -command “& ‘c:\scripts folder\myscript.ps1′”

Ok.. but why this simple action is post? Well sometimes after having run this task the “Task Run Result” shows you that the task has run correctly but not all the commands in your script completed. What’s going on here, man?

Well the task runs correctly, and after the script was executed the OS closes the Powershell session and does not wait.. So to prevent this behaviour (as like at so many Sharepoint cases) let’s insert a start-sleep -seconds 5 command at the end of your pws script 🙂

 

“powershell scheduled task”

Advertisements

4 thoughts on “Schedule powershell script”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s