none
Create mail box exchange 2007 + ASP.net RRS feed

  • Question

  • Hi,

    I want create mail box in asp.net but i have error in line

    System.Management.Automation.PSSnapInInfo snampInfo = runspaceConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out snapEX);

    an error is returned Microsoft.Exchange.Management.PowerShell.Admin it is not installed this machine "
    I don't have this problem in console project just in project asp.net(iisexpress).

    Thank you for Help.

    *****************************************************

    My Code

     //Create a Runespace and add commands
                RunspaceConfiguration runspaceConfig = RunspaceConfiguration.Create();
                PSSnapInException snapEX = null;
                System.Management.Automation.PSSnapInInfo snampInfo = runspaceConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out snapEX);
                Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfig);
                runspace.Open();

                //Creates a pipeline
                Pipeline pipeLine = runspace.CreatePipeline();

                using (pipeLine)
                {

                    //creates a  command
                    Command createMailbox = new Command("Enable-Mailbox");
                    createMailbox.Parameters.Add("Identity", Session["User"].ToString());

                    // now you must pass secure string
                    string pword = "CGvak123";
                    char[] passwordChars = pword.ToCharArray();
                    SecureString password = new SecureString();
                    foreach (char c in passwordChars)
                    {
                        password.AppendChar(c);
                    }


                    createMailbox.Parameters.Add("Database", "TOTO\\First Storage Group\\Mailbox Database");

                    //set other mailbox parameters here

                    pipeLine.Commands.Add(createMailbox);

                    Collection<PSObject> result = pipeLine.Invoke();


                }

                //closes connections
                pipeLine = null;
                runspace.Close();
                runspace = null;
                Response.Write("Mail Box Created Successfully!!!");
            }

            catch (Exception E)
            {
                Response.Write(E.ToString());
            }

                   
    Friday, November 13, 2015 9:23 AM