0

I need to edit a powershell script that creates new users and add a section that creates them a mailbox, problem I am having is that I need it to check the first letter of the username to determine whether it creates it in 'Store A-M' or 'Store A-Z' databases. From what I can tell I can import exchange module into powershell (I won't be in exchange shell) and use the enable-mailbox cmdlet, just having problems trying it all in . Any help would be appreciated

Edit: I am running exchange 2010 ona 2008R2 box, but will more than likely run the script from a 2012 R2 server.

1 Answers1

0

I use these commands to create a session and import the module, so that I don't have to use EMS:

New-PSSession -Name Exchange -ConfigurationName Microsoft.Exchange -ConnectionUri http://exchangeserver.domain.com/powershell/ -AllowRedirection -Authentication Kerberos
Import-Module (Import-PSSession (Get-PSSession -Name Exchange)) -Global

Once you have the modules imported, you can enable a mailbox like so (assuming you have your user's details already):

$mailstore = ""
if($user.Surname[0] -le 'M')
    { $mailstore = "Store A-M" }
else
    { $mailstore = "Store N-Z" }

Enable-Mailbox -Identity $user.samAccountName -Database $mailstore

I haven't added all the parameters you might want for the Enable-Mailbox command, as there are potentially lots of them and they aren't relevant to the question. You can see here for more info.

john
  • 1,995
  • 2
  • 17
  • 30