I have a wonderful script from Exchange Server Pro
that I'e modified a bit to meet my needs. This script is typically run using parameters to provide instructions for its execution. It looks like this:
.\Get-MailboxReport.ps1 -customAttribute1 hcca -filename hcca.csv
I've created a second powershell script that contains a number of lines like above to create separate .csv files for each of our shared services members. The script also emails the appropriate .csv to each client.
This second script works perfectly but I need to schedule this as a task. So I created a .bat file with these contents:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; C:\Scripts\Exchange2010\Get-MailboxReport\GenAllReportsAndMail.ps1"
If I run the .bat file interactively from the Exchange Management Shell it executes perfectly. When it is run from the task scheduler the script runs but does not seem to execute the parameters after the Get-MailboxReport.ps1 on any of the lines.
The script which normally takes 90 minutes to complete finishes in 2 minutes without recording any errors but none of the .csv files are actually created.
Any ideas how I can make this work as a scheduled task?