Scheduled task not working

Hi all,

I have a .ps1 script that runs some Exchange commands.When executing from Exchange management shell it works.

Command when run directly from Exchange management shell:

.\Get-ExchangeEnvironmentReport -HTMLReport C:\Scripts\ExchangeReport.html -SendMail:$true -MailFrom:postmaster@domain.com -MailTo:user1@domain.com -MailServer:mail.domain.com

But when i run from scheduled task it says success,but no email is sent.

Here its how ik look in Scheduled task:

Action: start a program

Program/script: powershell (also tried powershell.exe)

Add arguments: -c "pushd C:\scripts; C:\scripts\Get-ExchangeEnvironmentReport.ps1 -HTMLReport C:\Scripts\ExchangeReport.html -SendMail:$true -MailFrom:postmaster@domain.com -MailTo:user1@domain.com -MailServer:mail.domain.com"

I guess it failes because powershell doesnt understand Exchange commands,so i tried this:

-command ". 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; C:\Scripts\Get-ExchangeEnvironmentReport.ps1" -HTMLReport C:\Scripts\ExchangeReport.html -SendMail:$true -MailFrom:postmaster@domain.com -MailTo:user1@domain.com -MailServer:mail.domain.com"

This one also failed.Any idea how to get this working?

t

April 26th, 2015 7:51am

Trying removing the switch from the task and write it into the bottom of the script. So it's hard coded into the script and doesn't rely on that switch.
Free Windows Admin Tool Kit Click here and download it now
April 26th, 2015 10:10am

Basically remove the -sendmail and write that info into the script Send-MailMessage -To <towhoever@whatever.com> -From <fromwhoever@whatever.com> -bodyashtml -body $body -subject <whatever> If you need help with it, send me the script and I'll write it in for you.
April 26th, 2015 10:57am

Hi Josh and thanks for your tip,will try so and see if it helps.
Free Windows Admin Tool Kit Click here and download it now
April 27th, 2015 8:06am

Did try as you mentioned but it still fails.Had to add argument in the script to load Exchange comandlets then it worked! :)

thanks for your time.

April 27th, 2015 2:46pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics