No one has responded to this discussion for at least a year, so this information may be out of date. If you're looking for information about this topic, please search for a more recent discussion or post a new question.

System.Management.Automation.Remoting.PSRemotingTransportException

  • This post has 26 Replies |
  • 2 Followers
  • Hello,

           I am trying to execute my exchange server monitoring commands using a C# application(I have successfully tested this with power-shell console). I have used the following code in my C# project. 

    <pre>

    try
                {
                    string userName = @"abc\Administrator";
                    string password = "xxx";


                    SecureString secureString = new SecureString();
                    foreach (char c in password) secureString.AppendChar(c);
                    secureString.MakeReadOnly();


                    PSCredential credential = new PSCredential(userName, secureString);


                    WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new
                   Uri("http://192.168.1.221/powershell/"),
                   "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential) {                      

                    AuthenticationMechanism = AuthenticationMechanism.Basic };


                    Runspace runspace = RunspaceFactory.CreateRunspace();
                    PowerShell powershell = PowerShell.Create();
                    PSCommand command = new PSCommand();
                    command.AddCommand("New-PSSession");
                    command.AddParameter("ConfigurationName", "Microsoft.Exchange");
                    command.AddParameter("ConnectionUri", new Uri("http://192.168.1.221/powershell/"));
                    command.AddParameter("Credential", credential);
                    command.AddParameter("Authentication", "Basic");


                    powershell.Commands = command;


                    runspace.Open();


                    powershell.Runspace = runspace;


                    Collection<PSSession> result = powershell.Invoke<PSSession>();
                    foreach (ErrorRecord current in powershell.Streams.Error)
                        MessageBox.Show(String.Format("The following Error happen when opening the remote 

                        Runspace: {0} | InnerException: {1}",
                         current.Exception, current.Exception.InnerException));


                    if (result.Count != 1)
                        throw new Exception("Unexpected number of Remote Runspace connections returned.");


                    powershell = PowerShell.Create();
                    command = new PSCommand();
                    command.AddCommand("Set-Variable");
                    command.AddParameter("Name", "ra");
                    command.AddParameter("Value", result[0]);
                    powershell.Commands = command;
                    powershell.Runspace = runspace;
                    powershell.Invoke();


                    powershell = PowerShell.Create();
                    command = new PSCommand();
                    const string CreateMailBoxScript = "new-mailbox -Name:’{0}’ -Password:(ConvertTo-SecureString 

                    {1}  -AsPlainText -Force) -WindowsLiveID:{2} -FirstName:{3} -LastName:{4} -DisplayName:’{5}’";
                    command.AddScript(string.Format(CreateMailBoxScript, "sxavier", "textboxwithmail", 

                      "s@hotmail.com", "Sebastian", "Xavier", "Sebastian Xavier"));
                    powershell.Commands = command;
                    powershell.Runspace = runspace;
                    powershell.Invoke();


                    runspace.Dispose();
                    runspace = null;
                    powershell.Dispose();
                    powershell = null;
                }
                catch (Exception Ex)
                {
                    MessageBox.Show(Ex.Message);
                }

    </pre>


    But I am ended up in an exception.


    <pre>

    System.Management.Automation.Remoting.PSRemotingTransportException:
    Connecting to remote server failed with the following error message : The WinRM client cannot process the request. The authentication mechanism requested by the client is not supported by the server or unencrypted traffic is disabled in the service configuration. Verify the unencrypted traffic setting in the service configuration or specify one of the authentication mechanisms supported by the server. To use Kerberos, specify the computer name as the remote destination. Also verify that the client computer and the destination computer are joined to a domain. To use Basic, specify the computer name as the remote destination, specify Basic authentication and provide user name and password. Possible authentication mechanisms reported by server: For more information, see the about_Remote_Troubleshooting Help topic.

    </pre>


    It would be a great help to me , if someone of you can help me.

    Thanking you in advance


    Sebastian

  • Hi Sebastian,

    I understand you have tested the PowerShell cmdlets with power-shell console successfully. Just would like to confirm are you running the c# code on the same computer with the Powershell console you test? According to the error message, it sounds the WinRM service failed the request to authenticate with Exchange online. I suggest you try to configure Windows PowerShell on the computer you are running the program and ensure the PowerShell console can connect to Exchange Online successfully.

    To install and configure Windows PowerShell, please refer to the following article:
    http://help.outlook.com/en-us/140/cc952756.aspx

    Since it's development related question, I also suggest you ask it in the Windows PowerShell forum.

    Windows PowerShell forum:
    http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/threads

    Thanks,
    Reken Liu

  • Yes, I am running my c# application from my local PC only, from which I have successfully executed Exchange commands in powershell console. And WinRM service is running both on server & my machine.

    Thanks for your reply

  • After enabling basic authentication of power-shell virtual directory in IIS, I have tried the same code as a console application and have a new exception..

    The term 'new-mailbox' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.


    When I tried to fetch data using getmailbox, I got another error as follows...


    Active Directory operation failed on WIN-010LMRATJ8N.abc.com. The supplied credential for 'abc\123' on Bind operation is invalid. Error Code: 0x31.


    anymore hep would be great


    Regards

    Sebastian

  • Hello sxavier,

    As far as the first error, it sounds as though you did not import the cmdlets. There are two sets of cmdlets, one from the Microsoft Online Services Module and another imported to PowerShell. To get both sets of cmdlets, run the following from PowerShell:

    $Creds = Get-Credential

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

    Import-PSSession $Session -AllowClobber

    Import-Module MSOnline

    Connect-MsolService –Credential $Creds

    If you need to download the Microsoft Online Services Module, please see Step 2 on the page http://onlinehelp.microsoft.com/en-us/office365-enterprises/ff652560.aspx 

    A reference for the cmdlets is available at http://onlinehelp.microsoft.com/en-us/office365-enterprises/hh125002.aspx

    As to your second error, it appears that the credential for the user specified is incorrect. Please check to see that the user you are signing in with is a valid administrator and that the password is correct.

    Hope this helps,
    Gary Moore
    Office 365 Community Forums Moderator

  • Hello Gary Moore,

    Thanks for your help.

    I have tried the following commands , But I got some exceptions... 




    Now, when I tried to install Microsoft Online Services Module I have got another error....

    "In order to install Microsoft Online services Module for windows powershell, you must have microsoft online services sign-in assistant version 7.0 or greater installed on this computer"

    But i was unable to find the download link of microsoft online services sign-in assistant version 7.0

    I would be grateful to you, for any more help.

    Regards

    Sebastian

  • Hello sxavier,

    The errors you are getting would be expected if you have not installed the Microsoft Online Services Module. I also understand that you're getting an error when trying to install the Module.

    The Microsoft Online Services Sign-in Assistant can be downloaded from http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=11859. Once that is installed, you should be able to install the Module and that should solve your problem.

    By the way, the new-mailbox cmdlet is in the cmdlets you were able to import before you got the error. You can use

    Get-Command New-Mailbox

    in PowerShell to confirm that. for more information on the New-Mailbox cmdlet, type

    Get-Help New-Mailbox

    Hope this helps,

    Gary Moore
    Office 365 Forum Moderator

  • Hi Gary,

    Thanks for your valuable time.

    I have downloaded and installed online services sign in assistant using following link.

    http://blogs.technet.com/b/hot/archive/2011/11/29/how-to-configure-user-passwords-to-never-expire-in-office-365.aspx

    But when I tried the commands I got the following error. (The username which I gave was user@domain.com )


    I hope you can further help me.


    Thanks
    Sebastian




  • Hello Sebastian,

    The credentials you provide must be the correct O365 email address and password of an Administrator on your account. Using the correct administrator credentials should clear up this problem.

    Thanks,

    Gary Moore
    Office 365 Community Forums Moderator

  • Hello Sebastian,

    I apologize for the inconveniences this issue may have caused you and your organization. Please confirm if you were able to use the correct administrator credentials, also if you are able to run the PowerShell cmdlet.

     

    Best regards,
    Sherika MSFT Support

  • Hello Sebastian,

    How are things going? 

    If you have any other questions or concerns, please do not hesitate to contact us. It is always our pleasure to be of assistance.

    Regards
    Samuel

    Samuel A Girod MSFT
  • I can run these commands using power-shell console. I have rechecked the credentials and that is correct.

    Regards

    Sebastian

  • Hi Samuel,

    I still can't execute this. I am fed up with this...

    Regards

    Sebastian

  • Hello sxavier,

     I am sory you are having so much problems and want to verify the steps you are taking to run the  PowerShell commands.
     I am going to detail some steps below.  I am providing a link to PowerShell v 2.0 below

    Please download PowerShell v 2.0 from this link http://onlinehelp.microsoft.com/en-us/Office365-enterprises/ff652560.aspx and install it.

    Follow the steps below carefully 1-6  to connect PowerShell to Exchange Online.

    1. Click Start > All Programs > Accessories > Windows PowerShell > Windows PowerShell. Right click it to run as administrator.

    2. Run the following command:    $LiveCred = Get-Credential


    3. In the Windows PowerShell Credential Request window that opens, type the credentials of an account in your cloud-based organization. When you are finished, click OK.


    4. Run the following command:


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


    Note The AllowRedirection parameter enables cloud-based organizations in datacenters all over the world to connect Windows PowerShell to the cloud-based service by using the same URL.


    5. Run the following command:
    Import-PSSession $Session


     If it fails with an error message we may need to set the Execution policy to allow running remote PowerShell scripts.
    Run Get-ExecutionPolicy .
    If the value returned is anything other than RemoteSigned, you need to change the value to RemoteSigned by running
    Set-ExecutionPolicy RemoteSigned


    import-module MSOnline


    get-module MSOnline will list all available MODULES


    6. Run the following command:     Connect-MsolService -Credential $LiveCred



    Please follow the steps outlined above carefully and report back on your progress.

    Best regards

    Samuel 

    Samuel A Girod MSFT
  • Hello Samuel,

              Thanks for quick reply & detailed steps.  I have tried those steps and found an exception in the last step. Here are the screens shots.



    I have given the correct credentials. I have used the same for windows login.

    Once again thanks for your help.


    Regards

    Sebastian

  • Hello Sebastian,

     Thank you for the update and your patience in allowing us to help you with this issue.

     I want you to do the following. This will run a PoerShell that gives you a black window instead of the blue window you have been using.

    Navigate to Start-> All programs ->Nicrosoft Online Services -> Microsoft Online Services Module  for Windows PowerShell.

    When you get the black PowerShell window repeat the commands from Step 2 to Step 6 and let me know if this was successful.

    Regards

    Samuel


    Samuel A Girod MSFT
  • Hi Samuel,


    Thanks once again for your help and support. I have followed your instructions and got an exception in the following command. Connect-MsolService -Credential $LiveCred


     


    There is another update on this issue. 
                I have set up a new Windows server 2008 R2 and configured Exchange server on it.  Then installed Visual studio in it and executed the C# program for retrieving mailbox details. That is working fine but still I can't execute this program from another PC in the same domain. 


    Thanks & Regards

    Sebastian

  • Hello Sebastian

    Thanks for the update. I am reviewing the PowerShell commands and it appears that you get the same error whether we use the blue or the black version .

    Can you modify the command that fails from your last try. Run the command as  Connect-MsolService  and then let it prompt for the credentials.

    Even if this fails try to run your program and report what happens.

    Regards

    Samuel

    Samuel A Girod MSFT
  • Hi Samuel, 

       I have done the changes as suggested by you, but the result is same.  Here I have given the steps I have followed...

    • $LiveCred = Get-Credential
    • $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://WIN-8T4IUB1NROG.exchange.mjs.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
    • Import-PSSession $Session
    • import-module MSOnline
    • Connect-MsolService

    Please correct me if I am wrong.


    Thanks 

    Sebastian

  • Hi sxavier,

    Thanks for your post and screen shot about the current situation. I apologize for any inconveniences this issue may have caused you and your organization. Please follow these steps to connect to our Exchange Online:

    1.  $LiveCred = Get-Credential

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

    3. Import-PSSession $Session

    4. Connect-MsolService

    To verify you are successfully connected run this command get-mailbox and press enter. If you still have additional questions or concerns regarding feel free to update the post.


    Best regards,
    Roger MSFT Support

  • Hi Roger,


    I have followed your steps and ended up in an error. Please review the screenshot below. 


    Regards

    Sebastian

  • Hi sxavier,

    Unfortunately, to connect to our Exchange Online you must use the Microsoft Online Services Module for Windows PowerShell by Navigate to Start-> All programs ->Microsoft Online Services Module for Windows PowerShell =>. Then, run the scripts above. If you have additional questions or concerns feel free to post on the forum.

    Best regards,
    Roger MSFT Support

  • Hello Roger, 

    Thank you for your continuing support.  I did the same as you suggested.  Please review the screenshot below. 


    Regards

    Sebastian

  • Hello sxavier,

    Thanks for the response and the screenshot.
    In reviewing the errors you have had with PowerShell it is always that the username or password is incorrect.

    Do you have any other admin credential you could try. It has to be an Office 365 administrator credential.
    Rerun the steps using the black PowerShell window and use this new credential when you run the Connect-MsolService commandlet.

    We are very close to resolving this. Please update the thread with the results


    Regards,

    Samuel.

    Samuel A Girod MSFT
  • Hello Samuel,

               Thank you for your continuing support.  

    Samuel A Girod MSFT Moderator
    Do you have any other admin credential you could try. It has to be an Office 365 administrator credential.
    Can you please clarify this(I feel sorry for only having limited knowledge in this area); What is an Office 365 Administrator credential? How can I get that? I read that office 365 is a paid service offered from Microsoft and this contains different components including Microsoft Exchange Online. Is it necessary to have an office 365 administrator to run Exchange server(2010) monitoring commands via a C# application. Thanks once again for your help. 


    Regards

    Sebastian

  • Hello Roger,

    Click on the URL i have provided here for you as it gives you instruction on how to add a domain in Office 365. Please let me know if you have further questions in regards to this issue.

    http://onlinehelp.microsoft.com/en-us/office365-enterprises/ff637620.aspx


    Kind Regards, 
    Mario Novoa
    O365 Technical Support

Page 1 of 2 (27 items) 1|2|