Register-schedulejob for exchange 2010

This topic contains 5 replies, has 3 voices, and was last updated by  Rob Simmers 3 years, 1 month ago.

  • Author
  • #25266

    Patrick Surber


    I am trying to run a scheduljob that gets information from an exchange 2010 server.

    I am running the command form a remote computer on which I imported the exchange cmdlets.

    I can run the command manually and it works fine.

    Command example: get-mailbox -Identity psutest | export-csv c:\temp\get_mailbox.csv

    As soon as I put the same command in a schedulejob, it fails.

    Command example: Register-ScheduledJob -Name mailbox2 -ScriptBlock {get-mailbox -Identity psutest | export-csv c:\temp\ScheduledTask\get_mailbox.csv}

    We I run the command from the task scheduler, It seems to end normally but when I run the command get-job I can see that the state is in status failed.

    I don't understand why? Any help would be appreciated.

    If I do the same with a command like get-process, it works fine even in the scheduled task so I think it is a problem related to exchange and the command get-mailbox.

    thank you.


  • #25267

    Don Jones

    You're letting the scheduled job default to run as the SYSTEM account. That doesn't have permissions off the local machine, and can't connect to Exchange.

  • #25270

    Patrick Surber

    hello Don,

    Thank you for your answer.

    I am running the task with a domain admin account. And if I run the same command directly from powershell it works.

    any ideas.



  • #25273

    Patrick Surber

    I also tried to run the schedule task directly on the exchange server and it doesn't work.

  • #25274

    Don Jones

    I didn't see the domain account on the Register-ScheduledJob command, sorry. That's something you might double-check.

    There could be several things wrong. Permissions come to mind first. It's also possible something in the command is expecting a full user profile to be loaded, which doesn't happen when Task Scheduler runs the command. Are you running the scheduled task with the *same* domain account that you use to test? Is the scheduled task running on the same machine you test on? Can you create a scheduled task that simply runs { Get-Command Get-Mailbox } and see if that succeeds (if it doesn't, then Task Scheduler is having problems finding the Get-Mailbox command, which is your problem). It's a little hard to really troubleshoot when I'm not in your environment with you, but in general I try to think of all the differences between what I'm running, and what Task Scheduler does, and then try and test each of those things individually.

  • #25275

    Rob Simmers

    If you look at the scheduled task, in what context is the task running?

    [attachment file="security.png"]

You must be logged in to reply to this topic.