Exchange Powershell Script not running when launched from batch file

I have a batch file which launches an exchange powershell script:

+++++++++++++ StartExport.bat  +++++++++++++
@ECHO OFF

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
	}
}



LoadExchangeTools

$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!
whenzAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

strivoliCommented:
Did you specify the credentials to be used when running this scheduled task?
0
whenzAuthor Commented:
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 ...

Regards,
0
SubsunCommented:
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..
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Exchange

From novice to tech pro — start learning today.