Exchange Powershell Script not running when launched from batch file

Posted on 2013-08-28
Medium Priority
Last Modified: 2013-09-02
I have a batch file which launches an exchange powershell script:

+++++++++++++ StartExport.bat  +++++++++++++

powershell.exe Set-ExecutionPolicy Unrestricted
powershell.exe -command "& {C:\opensystems\RuntimeScripts\ExportScript1.ps1 }"
+++++++++++++ StartExport.bat  +++++++++++++

Open in new window

+++++++++++++ ExportScript1.ps1  +++++++++++++
function LoadExchangeTools {
	if (-not (Get-pssnapin | ? {$_.name -like 'Microsoft.Exchange'})) {
		Add-PSSnapin Microsoft.Exchange.Management.PowerShell.e2010
		Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin


$OpenSystemsMailboxes = "OpenSystemsMailboxes"
$OpenSystemsAliasManaged = "OpenSystemsAliasManaged"

+++++++++++++ ExportScript1.ps1  +++++++++++++

Open in new window

The thing is that when I manually launch the StartExport.bat file the scripts runs through as expected.  I developed a small .exe file which launches the StartExport.bat and then nothing happens.  I see in the Windows Task Manager that powershell.exe runs for 2 seconds and then stops.  The .exe only launches the StartExport.bat, nothing else.

Any help is appreciated!
Question by:whenz
LVL 20

Expert Comment

ID: 39445320
Did you specify the credentials to be used when running this scheduled task?

Author Comment

ID: 39445366
I think I know what the problem is.

When I launch my .exe I see in the taskmanager the process powershell.exe*32.  When I launch the .bat file directly I see powershell.exe in the task manager.

Therefore it seems that something with the .exe is wrong ...

LVL 40

Accepted Solution

Subsun earned 2000 total points
ID: 39445417
Are you trying to run the exe file using "Run as administrator"?
Are you getting any error while running the code using exe?

Add start-transcript -path c:\temp\log.txt as a first line of your script and run it from exe. Once it is done then check the log.txt for any errors..

Featured Post

Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

In my humble opinion (IMHO), TouchDown from Symantec is the best in class for this type of application, but Symantec has end-of-lifed it and although one can keep using it, it will no longer be supported or upgraded.  Time to look for alternatives t…
Disk errors can be the source of sundry problems for the Exchange server, the most common one being that the database fails to mount.
how to add IIS SMTP to handle application/Scanner relays into office 365.
Loops Section Overview

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question