Quantcast
Channel: Exchange Server Development forum
Viewing all articles
Browse latest Browse all 7132

Error when opening a Remote Runspace using WSManConnectionInfo

$
0
0

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 = "http://schemas.microsoft.com/powershell/Microsoft.Exchange";
           System.Uri serverUri = new Uri(String.Format("http://{0}/powershell?serializationLevel=Full", "somemachine"));

            for (int i = 0; i < pwd.Length; i++)
            {
                securePwd.AppendChar(pwd[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;
                rs.Open();
                PowerShell psh = PowerShell.Create();
                psh.Runspace = rs;                
                     ...
                rs.Close();
            }


Viewing all articles
Browse latest Browse all 7132

Trending Articles