Solved

Getting frustrated to run an Exchange script via Task Scheduler

Posted on 2013-11-01
8
1,064 Views
Last Modified: 2013-11-07
Hi Experts,

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

They are:
Get-ExchangeEnvironmentReport  >> http://www.stevieg.org/2011/06/exchange-environment-report/
Test-ExchangeServerHealth >> http://exchangeserverpro.com/health-check-exchange-2010-mailbox-server/

Environment:
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 -MailFrom:me@domain.com -Mailto:me@domain.com -MailServer:smtp.domain.com

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 works....like:
.\Get-ExchangeEnvironmentReport.ps1 -HTMLReport c:\scripts\report.html -SendMail:$true -MailFrom:me@domain.com -Mailto:me@domain.com -MailServer:smtp.domain.com


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?
0
Comment
Question by:osagarana
  • 3
  • 2
  • 2
8 Comments
 
LVL 31

Expert Comment

by:LeeDerbyshire
ID: 39616396
Is the task configured to run with the credentials of the correct mailbox owner (i.e. the me@domain.com in your example)?
0
 
LVL 1

Author Comment

by:osagarana
ID: 39618068
Sorry. I did not understand your question LeeDerbyshire.
0
 
LVL 12

Expert Comment

by:Dave
ID: 39618591
Is user account control disabled in your test environment? There must be some differences.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 31

Expert Comment

by:LeeDerbyshire
ID: 39621120
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?
0
 
LVL 1

Accepted Solution

by:
osagarana earned 500 total points
ID: 39626109
Guys,

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.
0
 
LVL 1

Author Comment

by:osagarana
ID: 39626110
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.
0
 
LVL 12

Expert Comment

by:Dave
ID: 39626654
in that case you should get your points back...
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

We are happy to announce a brand new addition to our line of acclaimed email signature management products – CodeTwo Email Signatures for Office 365.
This article will help you understand what HashTables are and how to use them in PowerShell.
In this video we show how to create a Distribution Group in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >>…
how to add IIS SMTP to handle application/Scanner relays into office 365.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now