Activate and set user on exchange


  • Hello,
    I use Exchange 2007 and when I migrate user's account to Exchange messaging environnement, I usually do the manipulation through the MMC as I am not an expert with Power Shell. HOwever, I tried the below commands and copied them in a ps1 file. the ps1 worked pretty ok but I would need some help to enhance it :-S
    Get-mailuser -Identity 'GRAIG2011' | Disable-Mailuser -Confirm:$false
    Enable-Mailbox -Identity '' -Alias 'GRAIG2011' -Database 'EXCHser01\SG19\LOND'
    Get-mailBox -Identity 'GRAIG2011' | Set-MailBox -CustomAttribute2 "EXCHANGE" -CustomAttribute10 "LONDON"
    Get-mailBox -Identity 'GRAIG2011' | Set-Mailbox -emailaddresspolicyenabled:$False
    Get-mailBox -Identity 'GRAIG2011' | Set-mailbox -EmailAddresses,
    Get-mailBox -Identity 'GRAIG2011' | Set-Mailbox -emailaddresspolicyenabled:$True
    Many thanks in advance to highlight me.
    Thursday, July 21, 2011 7:35 AM

All replies

  • If you are assigning out-of-policy e-mail addresses, then you shouldn't set -EmailAddressPolicyEnabled:$True on the mailbox at the end, you should leave that set to $False.  You can do all of that on one line, and you might want to add a couple of properties:

    Get-MailBox -Identity 'GRAIG2011' | Set-MailBox -CustomAttribute2 "EXCHANGE" -CustomAttribute10 "LONDON" -EMailAddressPolicyEnabled:$False -EmailAddresses, -PrimarySmtpAddress -WindowsEmailAddress


    Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
    • Proposed as answer by emma.yoyo Friday, July 22, 2011 7:35 AM
    Thursday, July 21, 2011 5:48 PM
  • Hi Graig,

    Any updates?

    Frank Wang

    Friday, July 22, 2011 7:35 AM
  • Sorry 4 not getting back to you sooner.

    User is hosted on another messaging system (mailuser) and I need to include in the shell command the deactivation process.

    As a existing user, the account has some smtp email addresses that I would need to copy to the new Exchange account. I wish to keep the policy on but Could not manage to add email addresses with the policy on..

    Also I would need to add a X500 email address as pour Legacy Exchange DN has been changed and the user is not recognized from outlook interface using cached Exchange mode.

    many thanks,


    Friday, July 22, 2011 2:17 PM
  • If the user is on a different e-mail system, then you need a mail-enabled contact (MailContact) if the user doesn't need a Windows account, or a mail-enabled user (MailUser, as opposed to a MailboxUser) if the user is logging into your system.  Yes, you'll need to copy the e-mail addresses to the contact or user and you'll probably want to preserve the LegacyExchangeDN as a proxy X500 address.  Unfortunately, there's no easy way that I know of to convert a MailboxUser to a MailUser or MailContact, but you could automate that through a PowerShell script, although that would be an awful lot of work for a single user.

    Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
    • Proposed as answer by Ed CrowleyMVP Sunday, July 24, 2011 10:01 PM
    Sunday, July 24, 2011 10:01 PM
  • Thanks Ed,


    I knew it would not look that nice and thought the command that do the job could be enhance (see above) When I need to migrate a user from another messaging system (mailuser) to exchange system (mailbox).

    I prepare my above ps1 by replacing username by the correct user (CTRL + H) Paste the OU and add the email addresses (get-mailuser | list emailaddresses).

    Then I schedule my sp1 at 11pm for exemple as moving user to Exchange does let the user receiving from outside the company (User unknown because of latency in the sync even with a start-edgsesync).

    Then I copy the email hosted on the server using Transporter Management Console For Internet Mail and I complete the migration.


    My question was how I could enhance my script ? maybe with a variable such as $user in order to avoid the CTRL+H but I am not very good at variable and scripting :S

    I tried t combine my script with the infroamtion you passed me before incluiding the deactivation phase, and I get that:


    Get-mailuser -Identity 'GRAIG2011' | Disable-Mailuser -Confirm:$false

    Enable-Mailbox -Identity '' -Alias 'GRAIG2011' -Database 'EXCHser01\SG19\LOND'

    Get-mailBox -Identity 'GRAIG2011' | Set-Mailbox -emailaddresspolicyenabled:$False

    Get-mailBox -Identity 'GRAIG2011' | Set-MailBox -CustomAttribute2 "EXCHANGE" -CustomAttribute10 "LONDON" -EMailAddressPolicyEnabled:$False -EmailAddresses, -PrimarySmtpAddress -WindowsEmailAddress

    Get-mailBox -Identity 'GRAIG2011' | Set-Mailbox -emailaddresspolicyenabled:$True


    Many thanks in advance if you can help me to enhance it better.


    Tuesday, July 26, 2011 5:44 AM
  • One way to enhance it is to create a loop based on the output from the Import-CSV cmdlet, and put all your data in a CSV file instead of editing the script for each user.

    Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
    Tuesday, July 26, 2011 11:05 PM
  • Hello Ed,

    Thanks, I think it is a great idea. I do not manage to put all the command to gather (not really good at scripting) Could you please help me?


    I thought about a CSV file like :


    Identity,Database, EXCHser01\SG19\LOND


    And the script like:

    import-csv C:\SCRIPT\user.csv | foreach {disable-Mailuser -identity $_.identity -Confirm:$false} | {enable-MailBox -identity $_.identity -Database $_.Database}...

    Put I got stuck with compiling the command :-S any help would be more than welcome.


    Thursday, July 28, 2011 9:49 AM