none
Powershell - WinRM error while trying to get an existing PsSession RRS feed

  • Question

  • Hello,

    I want to use the cmdlet "Get-PsSession -ComputerName"  and  "Enter-PsSession -ComputerName"  to  get and join a remote powershell session which connects my Windows server 2008 R2 to Microsoft Exchange server.

    Well, i previously opened a "New-PsSession" to Microsoft Exchange with the method described in the online technet documentation (and this is working well)

    $mycreds = New-Object system.Management.Automation.PSCredential("userlogin@mydomain.onmicrosoft.com", $passwordSecure)

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://ps.outlook.com/powershell/" -Credential $mycreds -Authentication Basic -AllowRedirection -Name $sessionName

    ComputerName           : pod*****h.outlook.com ConfigurationName      : Microsoft.Exchange InstanceId             : 7fe3********0578c3 Id                     : 1 Name                   : mh*****bc1p6 Availability           : Available ApplicationPrivateData : {SupportedVersions, ImplicitRemoting, PSVersionTable} Runspace               : System.Management.Automation.RemoteRunspace State                  : Opened IdleTimeout            : 900000 OutputBufferingMode    : None DisconnectedOn         : ExpiresOn              :

     

     

    But when i open a new Powershell window, i try to get the current PsSession this this cmdlet i got an error :

    Enter-PSSession -ComputerName pod5****.outlook.com -UseSSL

    (i think i need to use SSL because the connection URI is https://ps.outlook.com/powershell/, am i true?)

     

    Error:

    Connect-PSSession : The remote session query failed for pod5******.outlook.com with the following error message: WinRM cannot complete the operation. Verify that the specified computer name is valid, that the computer is accessible over the network, and that a firewall exception for the WinRM service is enabled and allows access from this computer. By default, the WinRM firewall exception for public profiles limits access to remote computers within the same local subnet. At line:1 char:1 + Connect-PSSession -ComputerName po******sh.outlook.com -UseSSL + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     + CategoryInfo          : InvalidOperation: (System.Manageme...nConnectionInfo:WSManConnectionInfo) [Connect-PSSes    sion], RuntimeException     + FullyQualifiedErrorId : WinRMOperationTimeout,RemotePSSessionQueryFailed,Microsoft.PowerShell.Commands.ConnectPS    SessionCommand

     

    Secondly, i tryed a Test-WSMan cmdlet, but i also got an error :

    Test-WSMan -ComputerName pod51031psh.outlook.com

    error:

    Test-WSMan : <f:WSManFault

    xmlns:f="http://schemas.microsoft.com/wbem/wsman/1/wsmanfault"

    Code="2150859046" Machine="FT2-AFR-DSYN-01.afr.corp.local"><f:Message>WinRM

    cannot complete the operation. Verify that the specified computer name is

    valid, that the computer is accessible over the network, and that a firewall

    exception for the WinRM service is enabled and allows access from this

    computer. By default, the WinRM firewall exception for public profiles limits

    access to remote computers within the same local subnet.

    </f:Message></f:WSManFault>

    At line:1 char:1

    + Test-WSMan -ComputerName pod51031psh.outlook.com

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : InvalidOperation: (pod51031psh.outlook.com:Strin

       g) [Test-WSMan], InvalidOperationException

        + FullyQualifiedErrorId : WsManError,Microsoft.WSMan.Management.TestWSManC

       ommand

     

     

    Why this error is happening ?

    What can i do to join the existant PsSession ?

    Does something need to be unlocked by Microsoft?

    Is there another way  in powershell to re-use an etablished connexion to Exchange?

    I hope you can help me, i really need some

    Vincent Nunnari

    Tuesday, November 18, 2014 2:53 PM

All replies

  • Hi Vincent,

    according to your script,it seems like you are trying to connect to Exchange Online?

    If so these as to be installed on your computer:

    http://go.microsoft.com/fwlink/?LinkId=286152

    http://go.microsoft.com/fwlink/p/?linkid=236297

    Reboot and run this command as one line:

    Set-ExecutionPolicy RemoteSigned

    $LiveCred = Get-Credential

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $LiveCred -Authentication Basic -AllowRedirection

    $Import = Import-Pssession $Session -AllowClobber

    Import-Module MSOnline -verbose

    Connect-MSOLservice -Credential $LiveCred

    Hope this helped


    Please mark as helpful if you find my contribution useful or as an answer if it does answer your question. That will encourage me - and others - to take time out to help you. Thank you! Off2work

    Tuesday, November 18, 2014 8:22 PM
  • Hello,

    thanks for your answer but i still need some help.

    Connecting to Microsoft Exchange works fine. (by using "New-PSSession")

    But now, i want another process to join the existing Session. (and not by creating another New session with "New-PSSession" command).

    The new process must join the existing session to dialog with Microsoft Exchange.

    Exemple:

    1- The first powershell process is connecting to MS Exchange by creating a PsSession. (already working)

    2- The second powershell process is connecting to MS Exchange by re-using the existant PsSession (need help for this)

    Is it possible?

    My project is the following:

    Actually, i've got a web application in PHP (running on apache web server) which is executing a powershell script to connect to Microsoft Exchange.

    Each time an operation is done on the webApplication, a connexion to MsExchange is opened and closed... So, that's sucks! There is too many connections,  it's taking a lot of time and the operators are bored. So i would like to put a planned task on the windows server to open a connexion to MsExchange ONCE,  so the webApplication simply use this connexion to do any operations on MsExchange. Do you think it is possible?

    Thanks,

    Vincent Nunnari

    Wednesday, November 19, 2014 10:58 AM
  • please, anyone can help me?

    Friday, November 21, 2014 8:06 AM