Error with visual studio C# while creating exchange mailbox RRS feed

  • General discussion

  • I am building my code in C# to create exchange mailboxes and getting an error with :

    The Windows PowerShell snap-in 'Microsoft.Exchange.Management.PowerShell.Admin' is not installed on this computer.

    Exchange Management tools 2007 and 2010 are installed on my windows 7 machine .When checking the snapins in powershell it shows snapins are installed

    If I execute my script in powershell it works fine without any error but not powershell(x86) . So, I believe when I build my app its trying to execute in X86 powershell rather than normal powershell which is 64bit .

    PS C:\Users\kunnu> Get-PSSnapin -Registered | fl name

    Name : Microsoft.Exchange.Management.PowerShell.Admin

    Name : Microsoft.Exchange.Management.PowerShell.E2010

    Name : Microsoft.Exchange.Management.Powershell.Support

    Name : Quest.ActiveRoles.ADManagement

    and in X86 powershell it shows only Name : Quest.ActiveRoles.ADManagement installed .

    Here is my code in C# :

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Management.Automation.Runspaces;
    using System.Management.Automation.Remoting;
    using System.Collections.ObjectModel;
    using System.Management.Automation;

    namespace kunnu
        public partial class WebForm1 : System.Web.UI.Page
            protected void Page_Load(object sender, EventArgs e)

            //Testing of email account info .

            protected void Button1_Click(object sender, EventArgs e)
                    Label1.Text = "";

                    Runspace runSpace = getRunspace("Microsoft.Exchange.Management.PowerShell.E2010");
                    Pipeline pipeline = runSpace.CreatePipeline();
                    pipeline.Commands.AddScript(@"C:\Users\kunnu\Desktop\kunnu\email.ps1 " + TextBox1.Text);
                    Collection<PSObject> results = pipeline.Invoke();
                    foreach (PSObject obj in results)
                        // Label1.Text = obj.Properties["Name"].Value.ToString();
                        Label1.Text = "Successfull";
                catch (Exception exception)
                    Label1.Text = "Operation Failed " + exception.Message;
    // Adding of Exchange snapin      
            public Runspace getRunspace(string snapIn)
                RunspaceConfiguration rsConfig = RunspaceConfiguration.Create();
                PSSnapInException snapInException;
                PSSnapInInfo snapinInfo = rsConfig.AddPSSnapIn(snapIn, out snapInException);
                Runspace runspace = RunspaceFactory.CreateRunspace(rsConfig);
                return runspace;


    Note:  email.ps1 contains only one line script which is  "get-mailbox -identity <userid> ". Any suggestions or ideas what I am doing wrong ...

    Thanks in advance .

    Monday, September 30, 2013 10:41 AM