troubleshooting Question

Exchange Powershell Script not running when launched from batch file

Avatar of whenz
whenz asked on
ExchangePowershell
3 Comments1 Solution647 ViewsLast Modified:
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  +++++++++++++


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


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!
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros