R – powershell exchange : how do you setup a scheduled task to run exchange2007 powershell

exchange-server-2007powershellscheduled-taskswindows

I'm having trouble setting up a scheduled task (now called Task Scheduler) under the actions tab to run on windows 2007 server. It also has exchange server 2007.

I've tried setting

Program/script : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Add arguments (optional): -psconsolefile exshell.psc1 -command "& {c:\mes-detail\emsbilling08.ps1}"
Start in (optional): "C:\Program Files\Microsoft\Exchange Server\Bin\

I realize the exshell.psc1 probably also needs an explicit path so I've also tried:

-psconsolefile C:\Program Files\Microsoft\Exchange Server\Bin\exshell.psc1 -command "& {c:\mes-detail\mailall3.ps1}" as well but that doesn't work either

Any ideas?

Best Answer

I figured I'd share the resolution here to finish what is started.

1) In your .ps1 file put Add-PSSnapin exchange

2) for the scheduled task, do this: Program/script : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe Add arguments (optional): -noprofile -Noninteractive c:\mes-detail\emsbilling08.ps1 Start in (optional): "C:\Program Files\Microsoft\Exchange Server\Bin\

If it still doesn't work, run the following checks:

Start...Run C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile

Get-PSSnapin -Registered

Do you see Microsoft.Exchange.Management.PowerShell.Admin Microsoft.Exchange.Management.Powershell.Support

If so, do add-pssnapin exchange

Related Topic