GAL import and export - Exchange 2007 RRS feed

  • Question

  • Hello,

    Sorry I'm not an Exchange person, but have the task to update our GAL as we have an Italian and French office with old email users and email address in the current GAL.

    I think I need to use this command to export ours to csv for those countries to update, but need first name, last name, job title, tel, smtp included how do I do this?

    Get-Recipient | Select-Object Name,PrimarySmtpAddress | Export-CSV -Not c:\temp\GAL.csv

    They have sent me theirs, but how do I import and also remove te current addresses?


    • Edited by TB303 Monday, January 27, 2014 3:18 PM
    Thursday, January 23, 2014 9:43 AM


  • Sorry, I should have caught that - yes, it should be -ExternalEmailAddress on creating the contact.  Keep in mind, though, that if your export file calls in "WindowsEmailAddress", your import will need to say "-ExternalEmailAddress $_.WindowsEmailAddress" ...
    • Edited by Will Martin, PFE Monday, January 27, 2014 5:27 PM
    • Marked as answer by TB303 Tuesday, January 28, 2014 12:40 PM
    Monday, January 27, 2014 5:26 PM

All replies

  • Add the fields you need to your Select statement:

    Get-Recipient | Select-Object Name, FirstName, LastName, Title, Phone, PrimarySmtpAddress | Export-CSV -Not c:\temp\GAL.csv

    As for setting this info on existing mailboxes, use the Set-User command (in fact, you may wish to use the Get-User command to pull the information in the first place):

    Set-User -Identity <Sam Account Name> -FirstName '<fname>' -LastName '<lname>' -Title '<title>' -Phone '<phone>' -WindowsEmailAddress '<primary SMTP address>'

    Thursday, January 23, 2014 12:46 PM
  • Is there a Get-Recipient command to pull all fields to csv so I can take a look?
    Thursday, January 23, 2014 2:31 PM
  • Sorry what is the difference between set-user and get-user? Is one export and one import?
    Thursday, January 23, 2014 3:32 PM
  • If you want to pull all fields of all recipients in your organization, run "Get-Recipient | Select * | Export-Csv c:\Temp\GAL.csv -NoTypeInformation"

    In PowerShell, Gets read information and Sets write it.  So Get-User reads information about user objects, and Set-User writes specific fields for user objects.

    Thursday, January 23, 2014 4:41 PM
  • Thanks I managed to export our GAL using:

    Get-User -Resultsize Unlimited| Select-Object Name,
    FirstName, LastName, Title, Company, City, CountryOrRegion, HomePhone,
    MobilePhone, WindowsEmailAddress | export-CSV c:\GAL-Export\gal.csv

    I also have the GALs from the other countries, now is the difficult part on how I remove the old addresses from Exchange and add the new ones in, something I have never done before.

    Maybe I should try a CSV with just one user in it, but I'm not sure of the import commands.

    Friday, January 24, 2014 12:22 PM
  • Looks like you could use a good book on PowerShell programming.  Assuming your import file is a CSV named TestImport.csv, here's what your command might look like:

    Import-Csv TestImport.csv | foreach { Set-User $_.Name -FirstName $_.FirstName -LastName $_.LastName -Title $_.Title -Company $_.Company -City $_.City -CountryOrRegion $_.CountryOrRegion -HomePhone $_.HomePhone -MobilePhone $_.MobilePhone -WindowsEmailAddress $_.WindowsEmailAddress }

    This will take the fields you exported and apply them to whatever accounts are in the TestImport.csv file.  You can then take the file from the other group and do the same thing.  However, are you adding contacts for these users, or are they going to have Windows accounts in your system?  If the former, you will need to use the Set-Contact command instead of the Set-User command.

    Friday, January 24, 2014 12:53 PM
  • Hi,

    If you just want to change the email address for users, maybe we can use E-mail address policy to achieve it. E-mail address policies which were known as Recipient Policies back in Exchange 2000 and 2003, define the proxy addresses that are stamped onto recipient objects in the Exchange 2007 organization. E-mail address policies are added on an organization level meaning they apply to the whole Exchange 2007 organization. For your reference:

    Managing E-Mail Address Policies in Exchange Server 2007


    E2K7: Creating Custom SMTP E-mail Address Policies Utilizing Various Replacement String Combinations


    Hope it helps.

    Winnie Liang
    TechNet Community Support

    Friday, January 24, 2014 5:30 PM
  • If the user is mail-enabled and their primary SMTP proxy address is different to the "WindowsEmailAddress" you'll break the Offline Address Book generation by running that bit of code.

    Caveat implementer!

    --- Rich Matheisen MCSE&I, Exchange MVP

    Saturday, January 25, 2014 8:18 PM
  • They won't have Windows accounts, these are just contacts

    I would like to add each country to it's own AD OU, I guess it would look like this?

    Import-Csv TestImport.csv | foreach { Set-User $_.Name -FirstName $_.FirstName -LastName $_.LastName -Title $_.Title -Company $_.Company -City $_.City -CountryOrRegion $_.CountryOrRegion -HomePhone $_.HomePhone -MobilePhone $_.MobilePhone -WindowsEmailAddress $_.WindowsEmailAddress -OrganizationalUnit "!Office Italy"}

    A power shell book looks like a good idea, but I think Exchange will be managed and hosted soon.

    Monday, January 27, 2014 12:27 PM
  • If you are using contacts, as I said, make sure you use the Set-Contact command.  Also, if you are putting them in separate OUs, and they don't already exist, you need to use the New-MailContact command and the full path to the OU.  So here's the expected syntax:

    New-MailContact -ExternalEmailAddress <smtp address> -Name "<full name>" -Alias <alias> -FirstName <first name> -Initials <initials> -LastName <last name> -OrganizationalUnit 'company.com/Office Italy'

    And even if you are going to be using hosted Exchange, you can do a ton of management actions with PowerShell.

    Monday, January 27, 2014 1:28 PM
  • I'm going to create a csv with just a dummy user in it and see if I can import it.

    I'll user just 4 columns, these are the names that seem to show at he top of the columns:

    Name, FirstName, LastName, WindowsEmailAddress

    name of the csv is test.csv and I will put it in the OU Company.com\Recipients\Italy

    I will try:

    Import-Csv test.csv | foreach { New-MailContact $_.Name -FirstName $_.FirstName -LastName $_.LastName  -WindowsEmailAddress $_.WindowsEmailAddress -OrganizationalUnit 'company.com\Recipients\Italy'}

    Does that look ok?

    Monday, January 27, 2014 3:44 PM
  • Sure does.  Once you have it working, if the CSV you get has the same fields and the contacts don't already exist, they should import just fine.  Good luck ...
    Monday, January 27, 2014 4:17 PM
  • The error I got was:

    New-MailContact : A parameter cannot be found that matches parameter name 'WindowsEmailAddress'.
    At line:1 char:139My export od the GAL uses 'WindowsEmailAddress' but should I be using -ExternalEmailAddress?

    Monday, January 27, 2014 4:27 PM
  • Sorry, I should have caught that - yes, it should be -ExternalEmailAddress on creating the contact.  Keep in mind, though, that if your export file calls in "WindowsEmailAddress", your import will need to say "-ExternalEmailAddress $_.WindowsEmailAddress" ...
    • Edited by Will Martin, PFE Monday, January 27, 2014 5:27 PM
    • Marked as answer by TB303 Tuesday, January 28, 2014 12:40 PM
    Monday, January 27, 2014 5:26 PM
  • They're still mail-enabled. The same caution applies to them. If the WindowsEmailAddress is different to the primary SMTP proxy address they won't appear in your OAB.

    --- Rich Matheisen MCSE&I, Exchange MVP

    Tuesday, January 28, 2014 4:29 AM
  • We only seem to have WindowsEmailAddresses, I've exported the GAL and don't see a Primary SMTP Proxy address?
    Tuesday, January 28, 2014 10:10 AM
  • Almost there, I want to import it into "domain.local\Recipients\!Italy Office" in AD but get this error:

    [PS] C:\Documents and Settings\admin-exchange>Import-Csv C:\AWGAL-Export\test.cs
    v | foreach { New-MailContact $_.Name -FirstName $_.FirstName -LastName $_.LastN
    ame -ExternalEmailAddress $_.WindowsEmailAddress -OrganizationalUnit "domain.local\Recipients\!Italy" }

    Organizational unit "domain.local\Recipients\!Italy" was not found. Please make sure you have typed it correctly.
    At line:1 char:49

    Tuesday, January 28, 2014 11:04 AM
  • In your domain, do you have a Recipients OU at the root level and does it have a child OU named "!Italy"?
    Tuesday, January 28, 2014 12:38 PM
  • Fixed it:

    -OrganizationalUnit "domain.local\Recipients\!Italy" }

    should of been

    -OrganizationalUnit "domain.local/Recipients/!Italy" }

    It has now imported.

    Thanks so much to you all, I appreciate it.

    Tuesday, January 28, 2014 12:40 PM
  • I'm creating a new Address List in the ESM and it askes for the name of the address list and then the container name, but it only lists currently container names, how can I create a new container name so it appears under he GAL?
    Tuesday, January 28, 2014 1:22 PM
  • Actually, this is a separate question.  If you post it separately, you will get more responses ...
    Tuesday, January 28, 2014 2:08 PM
  • You won't find those two properties on the same object. You have to look at the contact and mailcontact objects to get both of them.

    Something like this would work to point out differences:

    $contact = "aaaaa"
    $w = (get-contact $contact).WindowsEmailAddress.ToString()
    $e = (get-mailcontact $contact).PrimarySMTPAddress.ToString()
    if ($e -ne $w) 
      write-host "WindowsEmailAddress and PrimarySMTPAddress are different:"
      write-host "WindowsEmailAddress = $w"
    write-host "PrimarySMTPAddress  = $w"
      write-host "Addresses match"

    --- Rich Matheisen MCSE&I, Exchange MVP

    Wednesday, January 29, 2014 3:06 AM