My requirement is that when a user is created in my application, I need to create a mailbox in Exchange server 2010 for this user. I have the code that adds the user to Active Directory successfully. Now for adding the user to Exchange and creating mailbox, I use a windows application. My code is as below :

Here the code I have pasted is of command Get-User which connects to Exchange server and fetches the details of the user. Then if the user and his mailbox is not existing, I need to add it to Exchange server and create mailbox. But I am getting error as mentioned below :

System.Management.Automation.Remoting.PSRemotingTransportException: Connecting to remote server myserverip failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.
at System.Management.Automation.Runspaces.AsyncResult.EndInvoke()
at System.Management.Automation.Runspaces.Internal.RunspacePoolInternal.EndOpen(IAsyncResult asyncResult)
at System.Management.Automation.Runspaces.Internal.RemoteRunspacePoolInternal.Open()
at System.Management.Automation.RemoteRunspace.Open()

I have googled it a lot and tried with many options like checking user permissions, checking IIS settings where Exchange server is and Powershell is. I have tried Set-User UserName -RemotePowerShellEnabled $True and also tried Set-ExecutionPolicy RemoteSigned and many other things but nothing has worked so far.

One thing to note is that my windows application is hosted on different server and Exchange and Powershell are on different server, but both are in same domain.

Hi Hapex, it is possible to add user to Exchange and create mailbox using Powershell cmdlets.
–
DotNet WeblineindiaMay 21 '14 at 13:51

Okay, I thought there might be. But I ran into a similar issue in the past and just ran my PowerShell script with the Exchange Management Shell and everything worked. As long as I ran the script as my Doman Admin credentials (runas) it would add the user in Active Directory as well as Exchange.
–
HapexMay 21 '14 at 13:53

EMS is the best practice way of doing things. All the console does is generate and run powershell scripts in the background. And you can configure options in the Shell that aren't available in the Console.

Make sure you are apart of the Organization Management Group. Domain admins group I don't think is in it by default.

To enable remote Powershell management you will need to run something like "winrm quickconfig" but thats a sysadmin question because it touches on security, firewall rules etc that will be specific to your environment.

You would want to add more stuff to log and so forth. If you have multiple AD servers or the AD server and the Exchange server are not the same you need to make sure the user has propagated first or ensure that you create the user/mailbox on the same server so that you wont need to wait for propagation.

If you can't use the module and snapin due to sysadmin restrictions the user creation can be done via ADSI objects but thats a bit more work. Keep in mind that these scripts interact with a web service rather than direct ldap. So if you're passing via a load balancer/firewalls you may find that direct ldap queries pass but cmdlet ones don't.