Remote Exchange cmds wont work but in shell it does

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Luca Wirths Luca Wirths 1 year, 8 months ago.

  • Author
  • #32216
    Profile photo of Luca Wirths
    Luca Wirths

    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

  • #32218
    Profile photo of Noam lesnik
    Noam lesnik


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

  • #32219
    Profile photo of Luca Wirths
    Luca Wirths


    Thanks noam, that solved it.

You must be logged in to reply to this topic.