Link to home
Start Free TrialLog in
Avatar of whenz
whenz

asked on

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!
Avatar of strivoli
strivoli
Flag of Italy image

Did you specify the credentials to be used when running this scheduled task?
Avatar of whenz
whenz

ASKER

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,
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial