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

[E2013][C#][Windows]: Encountered an internal error in the SSL library

$
0
0

Scenario - 

I'm developing a .Net 4.0 based application on Window 7. It simply Enable-Mailbox for particular user over remote Exchange Server 2013.

ES 2013 is installed on Windows Server 2012. PowerShell v4.0 is installed on both development and remote server.

The following is the code snippet for same - 

// Global variables
const string ShellUri = "http://schemas.microsoft.com/powershell/Microsoft.Exchange";

        // URL for remote powershell
        const string ExchangeServerUri = " https://ExchangeServer.domain.com/powershell";

        const string ComputerName = "ExchangeServer.domain.com";
        const int Port = 5985; // If SSL=true then 5986
        const string ApplicationName = @"/wsman";
        const string Identity = "pabdul@domain.com";
        const string Database = "some db";
        const string DomainController = "XX.domain.com";

        // For credentials
        const string AdminUser = @"DOMAIN\Administrator";
        const string PlainPass = "password";

// PSCredential object
public PSCredential Credential
        {
            get
            {
                var password = ConvertToSecureString(PlainPass);
                var psCredential = new PSCredential(AdminUser, password);

                return psCredential;
            }
        }

// Function for enabling mailbox
private void EnableMailBoxNew()
        {
            object psSessionConnection = null;

            // 1. Create WSManConnectionInfo
            var wsManConInfo = new WSManConnectionInfo((new Uri(ExchangeServerUri)), ShellUri, Credential);
            wsManConInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos; 
            wsManConInfo.AppName = ApplicationName;
            wsManConInfo.Port = Port;
            wsManConInfo.UseCompression = true;

            // 2. Create runspace
            var runspace = RunspaceFactory.CreateRunspace(wsManConInfo);

            using (var powershell = PowerShell.Create())
            {
                // New-PSSession command
                var command = new PSCommand();
                command.AddCommand("New-PSSession");
                command.AddParameter("ConfigurationName", "Microsoft.Exchange");
                command.AddParameter("ConnectionUri", new Uri(ExchangeServerUri));
                command.AddParameter("Credential", Credential);
                command.AddParameter("Authentication", "Basic");

                PSSessionOption sessionOption = new PSSessionOption
                {
                    SkipCACheck = true,
                    SkipCNCheck = true,
                    SkipRevocationCheck = true
                };
                command.AddParameter("SessionOption", sessionOption);

                // Enable mailbox command
                //var cmdEnableMailbox = new Command("Enable-Mailbox");
                //cmdEnableMailbox.Parameters.Add("Identity", Identity);
                //cmdEnableMailbox.Parameters.Add("Database", Database);
                //cmdEnableMailbox.Parameters.Add("DomainController", DomainController);

                //powershell.Commands.AddCommand(cmdEnableMailbox);
                //powershell.Runspace = runspace;
                //var result = powershell.Invoke();

                powershell.Commands.Clear();
                powershell.Commands = command;
                runspace.Open(); // Open remote runspace
                powershell.Runspace = runspace; // Associate runspace with powershell
                var result = powershell.Invoke();

                if (result != null && result.Count > 0)
                {
                    psSessionConnection = result[0];

                    powershell.Commands = command;
                    powershell.Runspace = runspace;
                }
                else
                {
                    MessageBox.Show("New-PSSession is null! Can't proceed further.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            // Import remote exchange session into runspace
            if (psSessionConnection == null) return;

            // 3. Set ExecutionPolicy on the process to unrestricted
            using (var powershell = PowerShell.Create())
            {
                var command = new PSCommand();
                command.AddCommand("Set-ExecutionPolicy");
                command.AddParameter("Scope", "Process");
                command.AddParameter("ExecutionPolicy", "Unrestricted");
                powershell.Commands = command;
                powershell.Runspace = runspace;

                powershell.Invoke();
            }

            // 4. Import session object to runspace
            using (var powershell = PowerShell.Create())
            {
                var command = new PSCommand();
                command.AddCommand("Import-PSSession");
                command.AddParameter("Session", psSessionConnection);
                powershell.Commands = command;
                powershell.Runspace = runspace;

                powershell.Invoke();
            }

            // 5. Now execute your complex queries
        }

Now on execution I am facing problem of Encountered an internal error in SSL library.

Could anyone suggest why I am being getting so error?


Vikram Singh Saini (Freelancer on Elance)



Viewing all articles
Browse latest Browse all 7132

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>