Bulk mailbox enable from csv

Nelesh_N
Nelesh_N used Ask the Experts™
on
I have a couple thousand users to migrate to a new Exchange 2007 cluster. The user already exist in Active Directory.

Just trying the scripting by doing this:
get-qaduser liblinktest2 | enable-mailbox -database "lexmbxpd1wcx\usg01"

I get:

The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.

Think I have a missing parameter
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Try:
Enable-Mailbox john@contoso.com -Database "MyServer\First Storage Group\Mailbox Database"

Author

Commented:
Okay cool that works, but I only have this information:
firstname, surname and samaccountname

Author

Commented:
and I need to user a get-content or import-csv because I have so many users to create
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Import-Csv recipients.csv | foreach { Enable-Mailbox -identity $_.Identity –Database"MyServer\First Storage Group\Mailbox Database"}
AkhaterSolutions Architect

Commented:
there is something missing in your statement

the users already exists in AD ok but what do you need exactly ?

when you say migrate you mean they arlready have mailboxes on anohter exchange server ?

you want to apply this to all AD users ? or are they in a specific OU ?

how you want to differentiate in which database they will be created ?

if you have them in AD why you want to import from csv to start with

Author

Commented:
So we're migrating users from sendmail to exchange but the accounts already exist in ad.
This is what I have so far:
Import-Csv c:\test.csv |
foreach {Enable-Mailbox -identity $_.Identity –Database "lexmbxpd1wc4\usg01" -PrimarySmtpAddress $_.PrimarySmtpAddress}

Wont have to differentiate databases for now because we're only doing 50 users or so a day, so I dont mind having to change the database manually when needed.

Now I have a different problem, I have to set the primary smtp address to something different, but I still need to keep the secondary addresses that are automatically populated as part of the email address policy.

Author

Commented:
From what is the alias created?
AkhaterSolutions Architect

Commented:
what do u mean by something different? Another domain?

Author

Commented:
yes another accepted domain
AkhaterSolutions Architect

Commented:
what do u mean by something different? Another domain?
AkhaterSolutions Architect

Commented:
well it wld be better to create another email address policy for them

Author

Commented:
So the email address policy will consist of all the accepted domains?
I will have problems with duplicate addresses then.
AkhaterSolutions Architect

Commented:
sorry i didnt understand the concern

Author

Commented:
See we had two email systems a sendmail system and and exchange environment. We are now moving users from sendmail which has a different smtp suffix of @liblink.xxx and the exchange guys had a suffix of @liberty.xxx. The address policy adds the @liberty.xxx address in. The users that are being moved cannot have a secondary smtp of @liberty.xxx because there might already be a user with that address. We have had these problem in the past. This is what I have so far:

Import-Csv c:\test.csv | foreach {Enable-Mailbox -identity $_.Identity –Database "lexmbxpd1wc4\usg01" -PrimarySmtpAddress $_.PrimarySmtpAddress }

Now I need to be able to disble the emailaddresspolicy - easy
add a secondary smtp address

Do I just pipe to the set-mailbox?
AkhaterSolutions Architect

Commented:
why not add another email address policy for users ur migrating and set it to give tem a primay address @newdomain.com?

Author

Commented:
can it be applied to a specific storage group?
AkhaterSolutions Architect

Commented:
u can set it on a specific user attribute

Author

Commented:
cool, but I cant do that right now. I have to just add the secondary smtp for now. Complications around the address policy being pulled from our exchange 2003 environment.
AkhaterSolutions Architect

Commented:
u can use the emailaddresses parameter for this

Author

Commented:
Import-Csv c:\test.csv | foreach {Enable-Mailbox -identity $_.Identity –Database "lexmbxpd1wc4\usg01" -PrimarySmtpAddress $_.PrimarySmtpAddress } |
Set-Mailbox -EmailAddresses $_EmailAddresses

Somethings wrong - it creates the mailbox but doesnt populate any email adresses???

Author

Commented:
The first part works great it even does not enable the emailaddress policy but when I add the set-mailbox cmdlet it doesnt add anything? could it be my .csv??
just has an extra column with the secondary smtp
AkhaterSolutions Architect

Commented:
no u dont pipe it add it inside the foreach loop

Author

Commented:
getting a different error...

[PS] C:\Windows\system32>Import-Csv c:\test.csv | foreach {Enable-Mailbox -ident
ity $_.Identity -Database "lexmbxpd1wc4\usg01" -PrimarySmtpAddress $_.PrimarySmt
pAddress -EmailAddresses $_EmailAddresses}

Enable-Mailbox : A parameter cannot be found that matches parameter name 'Email
Addresses'.
At line:1 char:160
+ Import-Csv c:\test.csv | foreach {Enable-Mailbox -identity $_.Identity -Datab
ase "lexmbxpd1wc4\usg01" -PrimarySmtpAddress $_.PrimarySmtpAddress -EmailAddres
ses <<<<  $_EmailAddresses}
    + CategoryInfo          : InvalidArgument: (:) [Enable-Mailbox], Parameter
   BindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.Exchange.Manage
   ment.RecipientTasks.EnableMailbox
AkhaterSolutions Architect

Commented:
after the enablemailbox add

; set-mailbox

Author

Commented:
this thing is killing me!!!
Import-Csv c:\test.csv | foreach {Enable-Mailbox -identity $_.Identity –Database "lexmbxpd1wc4\usg01" -PrimarySmtpAddress $_.PrimarySmtpAddress ; Set-Mailbox -identity $_.Identity -EmailAddresses $_EmailAddresses }

The operation could not be performed because 'liblinkTest@liberty.xxxt' could not be found.
At :line:1 char:157
+ Import-Csv c:\test.csv | foreach {Enable-Mailbox -identity $_.Identity –Database "lexmbxpd1wc4\usg01" -PrimarySmtpAddress $_.PrimarySmtpAddress ; Set-Mailbox <<<<  -identity $_.Identity -EmailAddresses $_EmailAddresses }
AkhaterSolutions Architect

Commented:
well it is probably because the mailbox didn't have time to get created yet... try to run them as separate scripts with a few min of difference between them

Author

Commented:
Thanks I did have a look at those posts, my script is very similar.
The problem I am having is with the variables or maybe with the csv.
If I substitute the variables with user data it works. When using the variable it throws this error:

Cannot bind argument to parameter 'Identity' because it is null.
At :line:1 char:56
+ Import-Csv c:\book.csv | foreach { Set-Mailbox -Identity <<<<  $_upn -EmailAddressPolicyEnabled $false -PrimarySmtpAddress $_smtp }
Import-Csv c:\book.csv | foreach { Set-Mailbox -Identity $_upn -EmailAddressPolicyEnabled $false -PrimarySmtpAddress $_smtp }

Open in new window

Book.csv
This works I tested it:

Import-Csv recipients.csv | foreach { Enable-Mailbox -identity $_.DisplayName -Alias $_.Username -Database 'Server\First Storage Group\Mailbox Database'}


the csv should look like this:

DisplayName, Username
DOMAIN.LOCAL/OU NAME/Display Name1, username1
DOMAIN.LOCAL/OU NAME/Display Name1, username2
Sorry made a mistake on CSV

DisplayName, Username
DOMAIN.LOCAL/OU NAME/Display Name1, username1
DOMAIN.LOCAL/OU NAME/Display Name2, username2

Author

Commented:
Thanks, that works, but the list that I have doesn't have the display name of the user that needs to be mail enabled. I only have a list that has the samaccountname - any way to get this to works with?
Solutions Architect
Commented:
try htis


Import-Csv c:\test.csv | foreach {Enable-Mailbox -identity $_.Identity –Database "lexmbxpd1wc4\usg01" -PrimarySmtpAddress $_.PrimarySmtpAddress -EmailAddressPolicyEnabled $false}

Open in new window

You can change the CSV to:


DisplayName, Username
DOMAIN\User1, User1
DOMAIN\User2, User2

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial