.net - How do I programatically create an exchange 2010 mailbox using C# -
I have been given a task to write a program to create a 2010 exchange mailbox automatically. My research tells me to use powers but I can not find the namespace for reference and I want some sample code. I got some code on the web but I do not know what is the namespace for PowerShell, I think This system can be. Management. Automatation But when I try to reference the namespace it is not present in the list of dots.
When I did this, I would like to download powerhales separately Not sure, this is still the case. You can get it from
Here is an example that will create a mailbox:
SecureString password = new SecureString (); String str_password = "pass"; String user name = "userr"; String live connection URI = "http://exchange.wenatex.com/Powershell?serializationLevel=Full"; Foreign language (four x in strap password) {password.AppendChar (x); } PSCredential credentials = new PSCredential (username, password); // Set connection connection WSManConnectionInfo connectionInfo = New WSManConnectionInfo ((new URI (liveIdconnectionUri), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", Credential); ConnectionInfo.AuthenticationMechanism = Authentication icon. Default; // Create a runspace on a remote path / return frequency type should be RemoteRunspace Runspace Runspace = System. Management. Automation. Rain spaces.Ran Spacefacture Crutanpress (connectioninfo); PowerShell powershell = PowerShell.Create (); PS Commands = New PS Commands (); Command.AddCommand ("Enable-Mailbox"); Command. Adpameter ("Identity", User Armoname); Command. Adapter ("alias", user name); Command. Adapter ("database", "mbxcbg_01"); Powershell.Commands = Order; Try {// Remote Runspace Runspace Open. open (); // Affiliate Runspace with PowerShell PowerShell Arnaces = Ranspace; // Open powershell to get results = powershell.Invoke (); } Hold (Exception Pre) {Console.WriteLine (ex.Message); } Finally // Set up the Runspace and Enable Trash Collection Runspace. Dishes (); Ranspace = Null; // Finally resolve the powers and set to free all the variables // to release any resources. Powershell.Dispose (); Powers = Faucet; }
Comments
Post a Comment