Remote Powershell from DB Server to the Exchange Box

Answered Remote Powershell from DB Server to the Exchange Box

  • Thursday, March 29, 2012 8:37 PM
     
      Has Code

    I have a Database Server that need to remote into the Powershell for Exchange 2010 on my Exchange box since you can no longer create a mailbox using VBA or VB.net (And these are improvements???).  The best I can get is PS2 - PS2 between the boxes.

    I don't need to verify credentials as I have them set through the execution policy to bypass.

    I have enabled the Exchange PS to accept remotes and it gave me the address EXCH2010.domain.com.  I thought that would be enough to make the code happy.

    New-Session -ConfigurationName Microsoft.Exchange -ConnectionUri EXCH2010.domain.com 

    However - this code takes no univeral paths. I tried the IP addres.  Doesn't take an IP either.

    What does this field take and how do I get it?

All Replies

  • Thursday, March 29, 2012 8:39 PM
     
     

    What is your error message?

    Wher did you get New-Session from?

    A Uri takes a protocol.

    http://host:port
    http://localhost:80/WSMAN

    The port is optional for common protocols.

    If you are tryingto use PowerShell remoting then it is New-PSSession not New-Session


    ¯\_(ツ)_/¯



  • Thursday, March 29, 2012 8:47 PM
     
     
    -ConnectionUri does not accept universal paths
  • Friday, March 30, 2012 4:33 AM
     
     Proposed Answer Has Code

    You should be able to create a new session with this command:

    New-PSSession -ComputerName EXCH2010.domain.com 


    Grant Ward, a.k.a. Bigteddy

    What's new in Powershell 3.0 (Technet Wiki)

  • Tuesday, April 03, 2012 7:00 PM
     
     

    Hey Big Teddy - and I can - it takes me to the Powershell on that server - not the Powershell for Exchange.  To create a new Mailbox - you have to remote into the Powershell for Exchange - not the Powershell for the Windows Server.

    I know it's confusing because I am confused just trying to clarify. Makes me wonder if anyone has ever successfully created Mailboxes remotely calling from a server to the Exch Box and accessing the Powershell for Exchange in doing it or if they just throw out it's a possibility.

    When the Scripting Guy himself has no documentation of it on his blog and hours of Google can't produce a viable connection - I am going with the latter.


    • Edited by lmargita Tuesday, April 03, 2012 7:00 PM
    •  
  • Tuesday, April 03, 2012 7:17 PM
     
     

    Perhaps you should switch to Bing. ;)

    I find this in 4.2 seconds using a bing search of "powershell remote exchange"

    http://blogs.msexchange.org/walther/2009/04/22/connecting-to-a-remote-exchange-2010-organization-using-remote-powershell/

    Karl


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer



    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})



  • Tuesday, April 03, 2012 7:20 PM
     
     

    Perhaps you should switch to Bing. ;)

    I find this in 4.2 seconds uding a bing search of "powershell remote exchange"

    http://blogs.msexchange.org/walther/2009/04/22/connecting-to-a-remote-exchange-2010-organization-using-remote-powershell/

    Karl


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer



    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})



    Did you read my original post?  Did you see what the original issue was? That is the code I have been trying to use but cannot make the connection because it will not accept a URL or IP address.
  • Tuesday, April 03, 2012 7:25 PM
    Moderator
     
     Answered

    The Exchange 2010 Remote Management Shell will always open on the local computer (you are running it from). Even if you are running the Exchange Management Shell directly on the Exchange server, you'll STILL be using remoting. The Exchange cmdlets you use will be Proxy Commands and will run on the remote Exchange server but you can run them from your interactive session the DB server.

    There are a few different types of remote connections to Exchange. One is interactive (Enter-PSSession), which you don't want. Then there are Automatic remote sessions and manual remote sessions. You are trying to create a manual session. I'll believe you'll find it to be much easier if you install the Exchange 2010 Admin tools and then simply open the Exchange Remote Management Shell.

    If you want to create one manually, I would still recommend installing the Exchange Management tools, but here is what you need:

    $URI is the VirtualDirectory for your PowerShell Remoting Endpoint (e.g. 'http://EXCH2010.domain.com/PowerShell")

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $URI
    Import-PSSession $Session

    You will still be in your local, interactive session on the DB server, but you'll have Proxy Command that run on the Exchange 2010 box remotely.

    Good Luck!

    -Dan


    Please click "Vote as Helpful" if this post was helpful to you. Thanks!

    • Proposed As Answer by Cruz_DanielModerator Tuesday, April 03, 2012 7:26 PM
    • Marked As Answer by lmargita Tuesday, April 03, 2012 8:30 PM
    •  
  • Tuesday, April 03, 2012 7:45 PM
     
      Has Code

    Perhaps you should switch to Bing. ;)

    I find this in 4.2 seconds uding a bing search of "powershell remote exchange"

    http://blogs.msexchange.org/walther/2009/04/22/connecting-to-a-remote-exchange-2010-organization-using-remote-powershell/

    Karl


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer



    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})



    Did you read my original post?  Did you see what the original issue was? That is the code I have been trying to use but cannot make the connection because it will not accept a URL or IP address.

    In your original post you show this:

    New-Session -ConfigurationName Microsoft.Exchange -ConnectionUri EXCH2010.domain.com

    In Henrik's blog, he shows:

    $Session = New-PSSession –ConfigurationName Microsoft.Exchange –ConnectionUri https://E2K10EX01/PowerShell/ –Credential $UserCredential

    I propose that nothing in your original post suggested you tried this:

    New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri HTTPS://EXCH2010.domain.com/PowerShell/
    Karl

    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer



    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})


  • Tuesday, April 03, 2012 8:02 PM
     
     

    Dan - you actually made sense.  Thank you.

    My goal is to be able to Invoke-Command and run a script from .ps1 file from my Database Server to the Exchange Box to create New User Mailbox accounts. 

    When the error came up that New-Mailbox was not a valid option, (which works in PS for Exchange) it was my understanding then that there must be some kind of difference between the two and I needed to remote directly to the PS for Exchange to run my code.