I have a handful of Exchange scripts that run automatically as scheduled tasks using an Active Directory service account that is a member of the Organization Management group (a default Exchange group). I am trying to migrate these scheduled tasks (via export/import) and copied my PowerShell scripts to the same drive and folder on another server, but they do not seem to work correctly on the new server.
When I run the scheduled tasks on the new server either manually or if they run themselves on schedule, the powershell.exe processes just takes up around 56 MB of RAM but 0% CPU utilization and sits there in that state. After a few minutes, the RAM usage slowly starts to drop until it's a little under 2 MB of RAM. Eventually, the scheduled tasks time out after the two hour maximum task runtime I have configured and the Task Scheduler shows the following error: "The last run of the task was terminated by the user (0x41306)".
Here is an example of one of my scheduled tasks that I am having trouble with on the new server:
- Run as: DOMAIN\ExchangeTask
- Run whether user is logged in or not
- Command: %SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
- Arguments: -command ". 'D:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; D:\Scripts\Generate-ExchangeMailboxDetailReport.ps1"
- Start in: D:\Scripts
- Start the task only if the computer is on AC power: Disabled
Both servers are Windows Server 2008 R2 Standard SP1. Both are running PowerShell 2.0. I have already configured the service account the scripts run as with the "Log on as a batch job" security right in Local Security Policy on the
server and also rebooted the server. Additionally, the service account is not restricted by which computers it is permitted to log on to in Active Directory. I have also tried the "Run with highest privileges" option, but this made no
difference. I checked to make sure that both RemoteExchange.ps1 and Generate-ExchangeMailboxDetailReport.ps1 exist at the paths specified on the new server and they do. I've also made sure to launch PowerShell as admin and run Set-ExecutionPolicy
Bypass beforehand.
If I launch a cmd.exe session as the DOMAIN\ExchangeTask account and then run the following command, the script runs and completes successfully in well under the two hour maximum allotted. Additionally, the powershell.exe process running as DOMAIN\ExchangeTask
quickly ramps up to around 170 MB and uses around 99% CPU the entire time it is executing.
%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -command ". 'D:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; D:\Scripts\Generate-ExchangeMailboxDetailReport.ps1"
This seems to tell me that there is nothing wrong with my command and argument strings nor my script, but that something else is going wrong when the Task Scheduler tries to run the task. But I have no idea what that might be.
Any help that could be provided on this issue would be appreciated.