Note that there are some explanatory texts on larger screens.

plurals
  1. POEnable exchange 2010 mailbox
    primarykey
    data
    text
    <p>I'm trying to create/enable a mailbox on an exchange 2010 server from C# code. Everywhere I look I see people using the code shown below.</p> <p>However I get the following error:</p> <p><em>The term 'Enable-Mailbox' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.</em></p> <p>What am I doing wrong?</p> <pre><code> SecureString password = new SecureString(); string str_password = "myPassword"; string username = "myUsername"; //FQDN is ofcourse the (fully qualified) name of our exchange server.. string liveIdconnectionUri = "http://FQDN/Powershell?serializationLevel=Full"; foreach (char x in str_password) { password.AppendChar(x); } PSCredential credential = new PSCredential(username, password); WSManConnectionInfo connectionInfo = new WSManConnectionInfo((new Uri(liveIdconnectionUri)), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential); connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Default; Runspace runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(connectionInfo); PowerShell powershell = PowerShell.Create(); PSCommand command = new PSCommand(); command.AddCommand("Enable-Mailbox"); command.AddParameter("Identity", "domainname.ltd/OUName/TestAcc Jap"); command.AddParameter("Alias", "TestAccJap"); command.AddParameter("Database", "DB-Name"); powershell.Commands = command; try { runspace.Open(); powershell.Runspace = runspace; powershell.Invoke(); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { runspace.Dispose(); runspace = null; powershell.Dispose(); powershell = null; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload