Remote Exchange cmds wont work but in shell it does

I have a problem with my script, It makes an AD-User und then it should make the mailbox too.
The AD-User is no problem but then in the Invoke command im gives me the mistake

+ CategoryInfo          : NotSpecified: (:String) [], RemoteException
+ FullyQualifiedErrorId    : NativeCommandError
+ PSComputerName        : myExchangeServer

Process is terminated due to StackOverflowException.

My Invoke-COmmand:

$UPN = #UserPrincipalName
$database = "DB01"
$EXSession = New-PSSession -computername "myExchangeServer.mydomain.local" -Credential $Credentials
Invoke-Command -Session $EXSession -ArgumentList $UPN, $database -ScriptBlock{
$UPN ,

Write-Host $UPN, $database
\\myExchangeServer\C$\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -version 2.0 -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto ; Enable-Mailbox $UPN -Database $database"

If I type the Enable-Mailbox on the Exchangeserver it works.
Does anyone see the mistake?

Thanks Luca


If you only want to run exchange PowerShell cmdlets remotely you can you PowerShell remoting for exchange as described here:


Thanks noam, that solved it.