Is there a definitive guide to programmatically creating Exchange mailboxes remotely?

I found guides that explain how to run PowerShell scripts on Exchange Server, but all the guides require the machine to be connected to a domain, and most of them seem to use workarounds, not best practices.

Is there a way to remotely connect to Exchange Server using C # .NET or VB.NET?

In fact, I want to connect to my Exchange server using administrator credentials (I would provide them, encrypt them in the program) and create a mailbox using a PowerShell script. It's all.

I would like to run the application as a console application, and as soon as I confirm the functionality, I can implement it in a web form or MVC application.

Any advice is appreciated!

+5
source share
1 answer

I recently encountered a similar problem, the code below helped me to implement functionality with a secure connection to a remote Exchange server.

Runspace remoteRunspace = null;
PSCredential psc = null;
// If user name is not passed used the credentials of the current farm account
if (!string.IsNullOrWhiteSpace(username))
{
    if (!string.IsNullOrWhiteSpace(domain))
        username = domain + "\\" + username;
    SecureString secpassword = new SecureString();
    if (!string.IsNullOrEmpty(password))
    {
        foreach (char c in password)
        {
            secpassword.AppendChar(c);
        }
    }
    psc = new PSCredential(username, secpassword);
}

WSManConnectionInfo rri = new WSManConnectionInfo(new Uri(RemotePowerShellUrl), PowerShellSchema, psc);
if (psc != null)
    rri.AuthenticationMechanism = AuthenticationMechanism.Credssp;
remoteRunspace = RunspaceFactory.CreateRunspace(rri);
remoteRunspace.Open();

Pipeline pipeline = remoteRunspace.CreatePipeline();
Command cmdSharePointPowershell = new Command(Commands.AddPSSnapin.CommandName);
cmdSharePointPowershell.Parameters.Add(Commands.AddPSSnapin.Name, MicrosoftSharePointPowerShellSnapIn);
pipeline.Commands.Add(cmdSharePointPowershell);
pipeline.Invoke();

Of course, you will have the usual configuration of user group membership, server permission for remote secure / insecure remote connection, etc. this article may help.

+6
source

All Articles