Exchange 2010 cmdlet - exit after "entering" RRS feed

  • Question

  • Hi,

    I'm writing a fairly detailed user exit process for my organisation, which does things like discover/archive the redirected folders, move/disable the account, etc.

    One of the functions I'm struggling with involves Exhange mailboxes.  We have Exchange 2010 SP3 RU7. 

    The script runs initially in a "clean" PowerShell 2.0 shell.  The account that executes the script will naturally require a variety of rights, including those on exchange.

    Since we can't simply import the Exchange module, I execute the remote exchange script that comes with Exchange ("C:\Program Files\Microsoft\Exchange Server\V14\Bin\RemoteExchange.ps1") - this is so that I can perform Exchange operations, such as checking for explicit permissions on a mailbox set and that it mets other conditions that make it okay to proceed.

    So far, so good.  My issue at this point is that I don't know how to close the remote connection without closing PowerShell altogether! When the remoteexchange.ps1 command is run, it changes the PowerShell context to one that runs as the Exchange computer account (delegated the permissions my user account had, if I'm not mistaken).

    Now I'm stuck in it! I want to "return" from the exchange processes to my normal shell afterwards, but I don't know how.  I've tried:

    PS C:\> enter-pssession -computername MYEXCHANGESERVER1
    [MYEXCHANGESERVER1]: PS C:\> . "C:\Program Files\Microsoft\Exchange Server\V14\Bin\RemoteExchange.ps1"
    (it loads with no errors but the commands don't come up  - I don't think that they are compatible with a PSSESSION.

    I'm sure there is some way to do it - the searches I have performed on the internet point me to the exchange script, but none of utilities of it ever involve closing it!

    Any help is appreciated - I'm happy to write most of this script myself, but this little bit has caused me to give up for a while :(

    enter/exit-pssession, but I'm still logged in as the exchange computer account. 

    Thursday, December 4, 2014 11:40 PM


All replies