locked
Hi create a user in Exchange from my application ASPnet RRS feed

  • Question

  • User-1200535045 posted

     

    Hi all I need to create a user  in Exchange from my application ASPnet could help?

     

    Carlos Juan
    Wednesday, July 8, 2009 6:11 PM

Answers

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 8, 2009 9:07 PM
  • User-1200535045 posted
    if the user already created in Active Directory there is only to enable the account. the code is here.
    just remember that you need the power shell  sdk.
     

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Management.Automation;
    using System.Management.Automation.Host;
    using System.Management.Automation.Runspaces;
    //using Microsoft.PowerShell.Commands;


    namespace test
    {
        public class test

        {
            public void HabilitarCuenta(string usuario,string dominio,string basedatos)
            {
                ICollection<PSObject> results;
                RunspaceConfiguration runspaceConf = RunspaceConfiguration.Create();
                PSSnapInException PSException = null;
                PSSnapInInfo info = runspaceConf.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out PSException);
                Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConf);
                runspace.Open();
                Pipeline pipeline = runspace.CreatePipeline();

                Command createMailbox = new Command("Enable-Mailbox");
                //createMailbox.Parameters.Add("identity", @"test.corp/usuarios/" + usuario);
                createMailbox.Parameters.Add("identity", dominio+"/usuarios/" + usuario);
                createMailbox.Parameters.Add("alias", usuario);
                createMailbox.Parameters.Add("database", basedatos);
                pipeline.Commands.Add(createMailbox);
                results = pipeline.Invoke();           
           
            }
        }
       
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 16, 2009 1:29 PM

All replies

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 8, 2009 9:07 PM
  • User-1200535045 posted
    if the user already created in Active Directory there is only to enable the account. the code is here.
    just remember that you need the power shell  sdk.
     

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Management.Automation;
    using System.Management.Automation.Host;
    using System.Management.Automation.Runspaces;
    //using Microsoft.PowerShell.Commands;


    namespace test
    {
        public class test

        {
            public void HabilitarCuenta(string usuario,string dominio,string basedatos)
            {
                ICollection<PSObject> results;
                RunspaceConfiguration runspaceConf = RunspaceConfiguration.Create();
                PSSnapInException PSException = null;
                PSSnapInInfo info = runspaceConf.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out PSException);
                Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConf);
                runspace.Open();
                Pipeline pipeline = runspace.CreatePipeline();

                Command createMailbox = new Command("Enable-Mailbox");
                //createMailbox.Parameters.Add("identity", @"test.corp/usuarios/" + usuario);
                createMailbox.Parameters.Add("identity", dominio+"/usuarios/" + usuario);
                createMailbox.Parameters.Add("alias", usuario);
                createMailbox.Parameters.Add("database", basedatos);
                pipeline.Commands.Add(createMailbox);
                results = pipeline.Invoke();           
           
            }
        }
       
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 16, 2009 1:29 PM