Getting frustrated to run an Exchange script via Task Scheduler

Hi Experts,

I am getting really frustrated to run two PowerShell Exchange scripts via Task Scheduler.

They are:
Get-ExchangeEnvironmentReport  >>
Test-ExchangeServerHealth >>

Windows 2008 R2
Exchange 2010

Problem >>
I have two environments:
Lab Environment: Both work via Task Scheduler and when I run manually.
Production Environment: Only if I run the scripts manually. Not via Task Scheduler.

The user I am using on my production environment is a member of Domain Admins + Organization Management.

If I log in the production environment I can run my scripts manually successfully.


How my Task is configured:

Run whether user is logged or not - checked
Run with high privileges - checked

Program/script: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Argument: -c "push c:\scripts; c:\scripts\Get-ExchangeEnvironmentReport.ps1 -HTMLReport c:\scripts\report.html -SendMail:$true

No matter what I do, the task seems to complete(according the history of the task - no erros whatsoever) but it does not send the report.


Initially I thought was my SMTP server, but if I run the script manually
.\Get-ExchangeEnvironmentReport.ps1 -HTMLReport c:\scripts\report.html -SendMail:$true

I already ran:
Set-ExecutionPolicy Unrestricted
Set-ExecutionPolicy RemoteSigned

No difference!


It is not a problem with the script. If I run manually it works. The same happens with the other script (Test-ExchangeServerHealth). If I run mannually it works. If I try to run via Task Scheduler, nothing happens.
I reckon it is a permission issue. But to be honest I am running out of ideas.

Any ideas?
Who is Participating?
osagaranaConnect With a Mentor Author Commented:

Thanks for your help. Believe or not I found my production Exchange is installed on D: and no C:
When I changed:
from: c:\scripts\Get-ExchangeEnvironmentReport.ps1
to: d:\scripts\Get-ExchangeEnvironmentReport.ps1
..everything started to work.

Best Regards and sorry for the inconvenience.
Is the task configured to run with the credentials of the correct mailbox owner (i.e. the in your example)?
osagaranaAuthor Commented:
Sorry. I did not understand your question LeeDerbyshire.
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Is user account control disabled in your test environment? There must be some differences.
As far as I can remember, when you create a Task, it asks you to provide a username and password when you finally click the OK button (or maybe it's just an option within one of the Task configuration pages now). If it did ask, or if you see the option anywhere within the Task configuration pages, did you supply the account name and password of the owner of the mailbox you are trying to send the email from?
osagaranaAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for osagarana's comment #a39626109

for the following reason:

I found the solution myself.
in that case you should get your points back...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.