Script Connect-Mailbox help

Hi all,

domain A (resource forest) and domain B (account forest)

in domain A, exchange SP2 :  ex: domain name: A   user logon account: sam1  User dispaly name: D1     exchange server name: mail

in domain B: ex: dommain name: B   user logon account: A1

Connect-Mailbox -Identity "D1" -Database 'mail.a.local\1st Storage Group\Mailbox Database' -User 'A\sam1' -Alias 'A1' -LinkedDomainController 'dc1.b.local'  -LinkedMasterAccount 'B\A1' -LinkedCredential $credential

I need to do this for 800 users and I thought I create the txt file with sourcedisplayName, Database, sourcelogon, Alias, linkedmasteraccount then use excel to create 800 above lines.

Connect-Mailbox -Identity "D1" -Database 'mail.a.local\1st Storage Group\Mailbox Database' -User 'A\sam1' -Alias 'A1' -LinkedDomainController 'dc1.b.local'  -LinkedMasterAccount 'B\A1' -LinkedCredential $credential

Connect-Mailbox -Identity "D2" -Database 'mail.a.local\1st Storage Group\Mailbox Database' -User 'A\sam2' -Alias 'A2' -LinkedDomainController 'dc1.b.local'  -LinkedMasterAccount 'B\A2' -LinkedCredential $credential

------

Is there a better way to script with powershell?

Thank you.

 

  • Edited by John JY Wednesday, November 17, 2010 5:37 PM err
November 17th, 2010 4:48pm

I need to do this for 800 users and I thought I create the txt file with sourcedisplayName, Database, sourcelogon, Alias, linkedmasteraccount then use excel to create 800 above lines.

Connect-Mailbox -Identity "D1" -Database 'mail.a.local\1st Storage Group\Mailbox Database' -User 'A\sam1' -Alias 'A1' -LinkedDomainController 'dc1.b.local'  -LinkedMasterAccount 'B\A1' -LinkedCredential $credential

Connect-Mailbox -Identity "D2" -Database 'mail.a.local\1st Storage Group\Mailbox Database' -User 'A\sam2' -Alias 'A2' -LinkedDomainController 'dc1.b.local'  -LinkedMasterAccount 'B\A2' -LinkedCredential $credential

------

Is there a better way to script with powershell?

Thank you.

 


Create your file in Excel, then save it as .csv (eg c:\somedir\userlist.csv)

In Powershell,

import-csv c:\somedir\userlist.csv | foreach-object {

Connect-Mailbox -Identity $_.sourcedisplayname -Database $_.database -User $_.sourcelogon -Alias $_.alias -LinkedDomainController 'dc1.b.local'  -LinkedMasterAccount $_.linkedmasteraccount -LinkedCredential $credential

}

When you import-csv, you get a collection of custom objects, one for each row.  Each object will have a set of property names that match the column headings, and the values will be the content of the cell for that column of the row.  Avoid using embedded spaces in your column headings.  If a column heading has embedded spaces, you end up with a property name with embedded spaces and then you have to qoute the property name to keep from confusing the parser - eg if you use a column heading of "linked master account", then you have to reference it as $_."linked master account" in your script.

Free Windows Admin Tool Kit Click here and download it now
November 17th, 2010 5:53pm

Hi John,

 

Please refer to Mjolinor’s reply.

 

Please do not hesitate to let me know if you have any questions.

 

Best regards,

 

Serena

November 22nd, 2010 1:55am

Hi Mjolinor,

You are a life saver.  It worked like a charm.

Thank you so much for your help.

Free Windows Admin Tool Kit Click here and download it now
November 22nd, 2010 4:04pm

Hi John JY,

Can you provide a sample how you setup your csv file?  I have to do this exact same thing.  However I also, need to perform the disconnect first, and then reconnect the mailboxes to new user accounts.

Any assistance is greatly appreciated.

September 17th, 2013 12:58am

Did you get this to work? We are currently migrating users to a new forest and need to relink over 1000 users to the new domain with Exchange.
Free Windows Admin Tool Kit Click here and download it now
August 23rd, 2015 12:36am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics