I've asked this question before without a real solution being provided to my problem. I've scheduled a single daily task (A Powershell .ps1) in the Windows task scheduler that executes a powershell .ps1 file. Within the .ps1 file I'm executing I'm calling multiple .ps1 files using "Invoke-Expression". All the scripts execute but the Exchange scripts are not completing because they are failing to make the required a connection to Exchange 2010. I've installed the Exchange 2010 tools on the server which I'm running scripts from but I'm not able to connect to the Exchange tools to run the queries.
THis is part of the script that is called from the scheduled task:
I tried to add the following code to the scripts that require exchange, I'm able to sucessfully connect to an exchange server but once the code is executed the script stops and does not continue. I know that I could easily call another script and solve my problem but i would like to be able to have a single script called from within the .ps1 file that the Windows scheduled task calls. How can I
& C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto"