by baba20009 at 2012-10-24 08:14:05
I followed up this link and I am able to email the report OK in exchange powershell, but I cannot get it to task schedule. We have exchange 2007 sp3.by DonJ at 2012-10-24 12:50:17
http://www.stevieg.org/2011/06/exchange … nt-report/
Here is the script that I need to place in Task scheduler:
in exchange powershell, i type:
Cd \â€program files\Microsoft\exchange server\scriptsâ€
.\Get-ExchangeEnvironmentReport -HTMLReport c:\Report.html -SendMail:$true -MailFrom:test1@domain.com -MailTo:test2@domain.com -MailServer:hub1.domain.com
Thanks
So, you would put those commands into a text file that has a .ps1 filename extension. In Task Scheduler, you would scheduleby Pat Richard at 2012-10-24 13:16:34
PowerShell.exe -File <filename>.ps1
Obviously, the task will need to run under a credential that has permission to run all of those commands.
If you’ve done this and it isn’t working, it would be helpful if you could share whatever error messages or status messages you’ve got. Look into the Event Log after running the task.
I wrote a blog post about this a while back, since it can be confusing. Take a look at http://www.ehloworld.com/133 and let me know if you still have questions.by baba20009 at 2012-10-24 14:47:14
I looked at your link yesterday spent couple hours tested using your scripts and the scheduler task would not run.by DonJ at 2012-10-24 15:18:40
I also used this suggesd scripts in Steve Goodman’s link and couldn’t get the scheduler to run:
To make the scheduled task working (without security warning)
1. Set-executionpolicy unrestricted
2. Make a new copy of your great script, as yours is/will be tagged “from internetâ€
Scheduled Task :
Command : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Argument : -command “. ‘D:\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1?; Connect-ExchangeServer -auto;C:\Get-ExchangeEnvironmentReport.ps1 -HTMLReport c:\ExchReport.html -SendMail:1 -MailFrom:exchange.reports@xxx.com -MailTo:czi@xxx.ch,GR_DISTRI_IT@xxx.com -MailServer:xxx-cas.xxx.comâ€
Note that I had to change -SendMail:$True to -SendMail:1 (at least while testing/executing from CMD)
***
You can’t directly run a .PS1. Windows doesn’t consider it an executable file type.by baba20009 at 2012-10-24 16:04:36
Consider putting the ENTIRE set of commands into a .PS1, and then schedule PowerShell.exe as I suggested above.
I just ran this command to produce the error:by DonJ at 2012-10-24 16:30:33
.\Get-ExchangeEnvironmentReport -HTMLReport c:\report.html -SendMail:$true -MailFrom:you@example.com -MailTo:you@example.com -MailServer:smtp.example.com -ScheduleAs:DOMAIN\user
I got the report OK through email but no schedule task created. Here was the error message:
"Attempting to schedule: powershell -c "pushd c:\program files\microsoft\exchange server\scripts; C:\program files\microsoft\exchange server\scripts\Get-Exchange… (above scripts)
ERROR: Value for ’ /TR’ option cannot be more than 261 character<s>. "
yesterday when I was manually creating the schedule task, application nor system eventS had any EVENTS.
Yup. That’s because the total length of the command is too long. That’s why folks generally put stuff into a batch file (or a .PS1, in the case of PowerShell), and run that. As I’ve suggested. Twice.by DonJ at 2012-10-24 16:32:49
BTW, what you want to do is what’s described at http://www.ehloworld.com/133. Only instead of using -command to run a really long command, you put the long command into a .PS1 file, and use -File to reference that file. If you’re using -command (or -c, if you’re abbreviating), you have to fall under the maximum path limit, which is why you’re getting that error from your previous post.by baba20009 at 2012-10-26 10:44:42
At http://www.ehloworld.com/133, he was able to use -command because his total command-line length fell under the limit.
I did putting in a .ps1 file and it did not work. No error produced. No event to view. can you type in what I should put under:by Zushakon at 2012-11-06 05:16:45
Program/script:
Add arguments:
Thanks
[quote="baba20009"]I did putting in a .ps1 file and it did not work. No error produced. No event to view. can you type in what I should put under:by Pat Richard at 2012-11-16 10:41:15
Program/script:
Add arguments:
Thanks[/quote]
Change to when User is logged and see if it works then.
Anything new on this? We’re here to help get it working.