Home > Back-end >  Unable to execute PowerShell script from batch in Exchange management Shell
Unable to execute PowerShell script from batch in Exchange management Shell

Time:03-08

I have a script for enabling OWA for users that I want to run from a batch file. From the Exchange Management Console it runs fine. Opening the Echange management console from the batch file works as wel, but the execution of the script for enabling the user will not run.

Here's my batch file:

PowerShell.exe -noexit -command ". 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; 'C:\Script\Exchange\OWA_access\enable_OWA_access_RM-versie.ps1'"

And this is the result:

     Welcome to the Exchange Management Shell!

 Full list of cmdlets: Get-Command
 Only Exchange cmdlets: Get-ExCommand
 Cmdlets that match a specific string: Help *<string>*
 Get general help: Help
 Get help for a cmdlet: Help <cmdlet name> or <cmdlet name> -?
 Exchange team blog: Get-ExBlog
 Show full output for a command: <command> | Format-List

 Show quick reference guide: QuickRef
 Tip of the day #50:

 Bla bla bla

 VERBOSE: Connecting to PROMAILVLZ-04.sfg.net.
 VERBOSE: Connected to PROMAILVLZ-04.sfg.net.
 C:\Script\Exchange\OWA_access\enable_OWA_access_RM-versie.ps1
 [PS] C:\Script\Exchange\OWA_access>

"C:\Script\Exchange\OWA_access\enable_OWA_access_RM-versie.ps1" is not executed, as you will be prompted for a username, which is not the case. If I run the file in this (current) "management shell" (C:\Script\Exchange\OWA_access\enable_OWA_access_RM-versie.ps1), it will run without issues.

Anyone?

Thanks in advance!

Richard

CodePudding user response:

You have issued a "return string" command, should you want to execute a ps1, you should & or . it instead, like you did with RemoteExchange.ps1.

  • Related