Remote Exchange cmds wont work but in shell it does

This topic contains 2 replies, has 2 voices, and was last updated by  Luca Wirths 2 years ago.

  • Author
    Posts
  • #32216

    Luca Wirths
    Participant

    Hi
    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 = luca.wirths@mydomain.com #UserPrincipalName
    $database = "DB01"
    $EXSession = New-PSSession -computername "myExchangeServer.mydomain.local" -Credential $Credentials
    Invoke-Command -Session $EXSession -ArgumentList $UPN, $database -ScriptBlock{
    param(
    $UPN ,
    $database
    )
    
    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

    Noam lesnik
    Participant

    Hi,

    If you only want to run exchange PowerShell cmdlets remotely you can you PowerShell remoting for exchange as described here:
    https://technet.microsoft.com/en-us/library/dd297932(v=exchg.141).aspx

  • #32219

    Luca Wirths
    Participant

    Hi,

    Thanks noam, that solved it.

You must be logged in to reply to this topic.