batmon34
asked on
How to add Scheduled Task for a Exchange Shell Script?
Hi,
I created a Exchange PowerShell script that can check LDAP and then create new mailboxes as needed. It works fine in the Exchange Management Shell (2007). I want it to auto run every few hours. I tried to add a scheduled task but it does not work. I chose "Exchange management Shell" as the type, It added as the following:
C:\WINDOWS\system32\WINDOW ~2\v1.0\po wershell.e xe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1" -noexit -command ". 'C:\Program Files\Microsoft\Exchange Server\bin\Exchange.ps1'"
If I want to run a script called newbox.ps1, how do I do it?
500 points.
Thank you.
I created a Exchange PowerShell script that can check LDAP and then create new mailboxes as needed. It works fine in the Exchange Management Shell (2007). I want it to auto run every few hours. I tried to add a scheduled task but it does not work. I chose "Exchange management Shell" as the type, It added as the following:
C:\WINDOWS\system32\WINDOW
If I want to run a script called newbox.ps1, how do I do it?
500 points.
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Did this work for you?
ASKER
BSonPosh,
Yes, it works. However, I scheduled to run every four hours and it only runs whenever it feels like it. So far for the past 2 weeks, it ran 3 times. If I "stop" and "run" manually, it will run too.
Any idea?
Yes, it works. However, I scheduled to run every four hours and it only runs whenever it feels like it. So far for the past 2 weeks, it ran 3 times. If I "stop" and "run" manually, it will run too.
Any idea?
Hmmm.... What do you mean by "only runs whenever it feels like it" You mean the schedule task or does the script only work occasionally?
ASKER
only work occasionally. I schedule it to run every 4 hours but it only manage to run it 3 times for the past 2 weeks.
So the task runs but fails? Why do you think it fails? Do you have any debug options in the script?
ASKER
How do I tell if it failed? The script will send email to me and I only receive 3 emails for the past 2 weeks.
I would add a line that writes to a local file just stating that the script actually ran. You could also write debug info there. It is entirely possible that the script ran, but the email failed.
ASKER
You are right. The log keeps saying
** WARNING **
The task was forced to close since its execution time exceeded the configured maximum.
You may want to go to the Settings page and increase the "Stop the scheduled task after" time.
If I stop the scheduled task, and then start it, it runs in seconds. When I try to run it with scheduled time, it keeps showing this message. The "Stop the scheduled task after" time is set 72 hours.
** WARNING **
The task was forced to close since its execution time exceeded the configured maximum.
You may want to go to the Settings page and increase the "Stop the scheduled task after" time.
If I stop the scheduled task, and then start it, it runs in seconds. When I try to run it with scheduled time, it keeps showing this message. The "Stop the scheduled task after" time is set 72 hours.
Is the schedule task running as an Admin?
Can you scrub the script and post it?
Can you scrub the script and post it?
ASKER
It works now. The default "Stop the scheduled task after" time is set 72 hours. I changed it to 1 hr and now my script runs every 4 hrs as the way I wanted. Go figure...
Thanks.
Thanks.
Try this: -
powershell.exe -noexit &'c:\newbox.ps1'
Running Windows PowerShell Scripts
http://www.microsoft.com/technet/scriptcenter/topics/winpsh/manual/run.mspx