Register-schedulejob for exchange 2010

This topic contains 5 replies, has 3 voices, and was last updated by Profile photo of Rob Simmers Rob Simmers 2 years ago.

  • Author
    Posts
  • #25266
    Profile photo of Patrick Surber
    Patrick Surber
    Participant

    Hello,

    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.

    patrick

  • #25267
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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
    Profile photo of Patrick Surber
    Patrick Surber
    Participant

    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.

    thanks.

    patrick

  • #25273
    Profile photo of Patrick Surber
    Patrick Surber
    Participant

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

  • #25274
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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
    Profile photo of Rob Simmers
    Rob Simmers
    Participant

    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.