Error when opening a Remote Runspace using WSManConnectionInfo RRS feed

  • Question

  • I got error "Connecting to remote server failed with the following error message : Logon failure: unknown user name or bad password. For more information, see the about_Remote_Troubleshooting Help topic." when the code run at  rs.Open(); 

    But this error seems to occurs occasionally, the error may show up in the morning, but the code is working fine in the afternoon. And then it shows up another day, but later it will be working again.

    Any advise would really appreciated. Thanks.

    Here is my code

                string pwd="somepassword";
                string SHELL_URI = "";
               System.Uri serverUri = new Uri(String.Format("http://{0}/powershell?serializationLevel=Full", "somemachine"));

                for (int i = 0; i < pwd.Length; i++)

                PSCredential psCredential = new PSCredential("someUserName", securePwd);
                RunspaceConfiguration rc = RunspaceConfiguration.Create();
                WSManConnectionInfo wsManInfo = new WSManConnectionInfo(serverUri, SHELL_URI, psCredential);

                using (Runspace rs = RunspaceFactory.CreateRunspace(wsManInfo))
                    wsManInfo.MaximumConnectionRedirectionCount = 1;
                    PowerShell psh = PowerShell.Create();
                    psh.Runspace = rs;                

    Thursday, July 18, 2013 1:44 PM


All replies