locked
Quick question about exporting email address and their alias from Exchange 2007 mailbox RRS feed

  • Question

  • Hi Everyone,

    We have Exchange 2007 and 2013 servers. All users are still 2007 servers. I have a list of users around 179 out of 3000 in a CSV file. I would like to export those 179 users primary smtp and their aliases. Is it possible to achieve through any script?

    Thanks in advance.

    Regards,

    Siva

    Tuesday, October 7, 2014 9:13 AM

Answers

  • Hello Siva,

    You don't need a script for this. Information can be obtained with simple command.

    $AllUsers = Get-Mailbox -ResultSize Unlimited | Select DisplayName,Alias,PrimarySMTPAddress,SamACcountName,Database,LegacyExchangeDN
    
    $AllUsers | Export-Csv Outputfile.csv -NoTypeInformation

    Try this and let me know if it helps!


    if you want PrimarySMTPAddress and alias of only those users whose information on the excel sheet, then what do you have as the column name in the excel sheet which you are using to query on the server.

    Considering that you are using Alias to query the server to get the details you can try below:

    $Global:Output = @() $CsvData = Import-Csv Inputfile.csv foreach($line in $CsvData) {

    $CurrentObject = $Line.Alias

    Write-Host “Processing Obect “$CurrentObject “From Csv File” –ForeGroundColor YELLOW

    $EmailIDJoin = ""

    $EmailAddresses = @()

    $UserInfo = "" | Select DisplayName,PrimarySMTPAddress,Alias,SamAccountName,Database,LegacyExchangeDN,EmailAddresses $UserInfo.DisplayName = (Get-Mailbox $CurrentObject).DisplayName $UserInfo.PrimarySMTPAddress = (Get-Mailbox $CurrentObject).PrimarySMTPAddress $UserInfo.Alias = (Get-Mailbox $CurrentObject).Alias $UserInfo.SamAccountName = (Get-Mailbox $CurrentObject).SamAccountName $UserInfo.Database = (Get-Mailbox $CurrentObject).Database $UserInfo.LegacyExchangeDN = (Get-Mailbox $CurrentObject).LegacyExchangeDN $EmailAddresses = (Get-Mailbox $CurrentObject)|%{$_.EmailAddresses} for($i=0;$i -lt $EmailAddresses.Count;$i++) { $EmailIDJoin += $EmailAddresses[$i].ProxyAddressString if($i -lt $EmailAddresses.Count - 1) { $EmailIDJoin += ',' } } $UserInfo.EmailAddresses = $EmailIdJoin $Global:Output += $UserInfo } #Export output to CSV File $Global:Output | Export-Csv GlobalOutput.csv -NoTypeInformation




    • Proposed as answer by PK M Tuesday, October 7, 2014 1:18 PM
    • Marked as answer by Sivakumar Margabandhu Tuesday, October 7, 2014 1:43 PM
    • Edited by PK M Wednesday, October 8, 2014 11:08 AM
    Tuesday, October 7, 2014 10:03 AM
  • If you want to Use DisplayName to query, then make sure to have a column DisplayName in the Excel. Make sure you don't have a space and it should be DisplayName

    You would just need to change this part:

    $CurrentObject = $Line.DisplayName

    And rest of the script will remain the same

    Ping back with the outcome.


    M.P.K ~ ( Exchange | 2003/2007/2010/E15(2013)) ~~ Please remember to click “Vote As Helpful" if it really helps and "Mark as Answer” if it answers your question, “Unmark as Answer” if a marked post does not actually answer your question. ~~ This Information is provided is "AS IS" and confers NO Rights!!

    Tuesday, October 7, 2014 1:18 PM

All replies

  • Hello Siva,

    You don't need a script for this. Information can be obtained with simple command.

    $AllUsers = Get-Mailbox -ResultSize Unlimited | Select DisplayName,Alias,PrimarySMTPAddress,SamACcountName,Database,LegacyExchangeDN
    
    $AllUsers | Export-Csv Outputfile.csv -NoTypeInformation

    Try this and let me know if it helps!


    if you want PrimarySMTPAddress and alias of only those users whose information on the excel sheet, then what do you have as the column name in the excel sheet which you are using to query on the server.

    Considering that you are using Alias to query the server to get the details you can try below:

    $Global:Output = @() $CsvData = Import-Csv Inputfile.csv foreach($line in $CsvData) {

    $CurrentObject = $Line.Alias

    Write-Host “Processing Obect “$CurrentObject “From Csv File” –ForeGroundColor YELLOW

    $EmailIDJoin = ""

    $EmailAddresses = @()

    $UserInfo = "" | Select DisplayName,PrimarySMTPAddress,Alias,SamAccountName,Database,LegacyExchangeDN,EmailAddresses $UserInfo.DisplayName = (Get-Mailbox $CurrentObject).DisplayName $UserInfo.PrimarySMTPAddress = (Get-Mailbox $CurrentObject).PrimarySMTPAddress $UserInfo.Alias = (Get-Mailbox $CurrentObject).Alias $UserInfo.SamAccountName = (Get-Mailbox $CurrentObject).SamAccountName $UserInfo.Database = (Get-Mailbox $CurrentObject).Database $UserInfo.LegacyExchangeDN = (Get-Mailbox $CurrentObject).LegacyExchangeDN $EmailAddresses = (Get-Mailbox $CurrentObject)|%{$_.EmailAddresses} for($i=0;$i -lt $EmailAddresses.Count;$i++) { $EmailIDJoin += $EmailAddresses[$i].ProxyAddressString if($i -lt $EmailAddresses.Count - 1) { $EmailIDJoin += ',' } } $UserInfo.EmailAddresses = $EmailIdJoin $Global:Output += $UserInfo } #Export output to CSV File $Global:Output | Export-Csv GlobalOutput.csv -NoTypeInformation




    • Proposed as answer by PK M Tuesday, October 7, 2014 1:18 PM
    • Marked as answer by Sivakumar Margabandhu Tuesday, October 7, 2014 1:43 PM
    • Edited by PK M Wednesday, October 8, 2014 11:08 AM
    Tuesday, October 7, 2014 10:03 AM
  • Hi Pavan,

    Thank you so much for your reply. I have the display name of those 179 users. I would like to use your script. How to modify it from alias to display name in that script.

    Thanks in advance.

    -Siva

    Tuesday, October 7, 2014 10:24 AM
  • If you want to Use DisplayName to query, then make sure to have a column DisplayName in the Excel. Make sure you don't have a space and it should be DisplayName

    You would just need to change this part:

    $CurrentObject = $Line.DisplayName

    And rest of the script will remain the same

    Ping back with the outcome.


    M.P.K ~ ( Exchange | 2003/2007/2010/E15(2013)) ~~ Please remember to click “Vote As Helpful" if it really helps and "Mark as Answer” if it answers your question, “Unmark as Answer” if a marked post does not actually answer your question. ~~ This Information is provided is "AS IS" and confers NO Rights!!

    Tuesday, October 7, 2014 1:18 PM