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!
ExchangePowershell

Avatar of undefined
Last Comment
Subash Sundharan

8/22/2022 - Mon
strivoli

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

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
Subash Sundharan

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy