none
Exporting multiple email addresses to CSV

    Question

  • Hello,

    Get-mailcontact -id juser |select-object emailaddress|export-csv c:\admin\email.csv doesn't properly export multiple email addresses. Does anyone know how I can obtain them and export to a csv?

    Thank you

    Wednesday, January 19, 2011 4:03 AM

Answers

  • This should create a comma separate list file of the mailcontacts names and all of their email addressses.


    $addrlist = get-mailcontact | foreach {
    @($_.name) + @($_.emailaddresses |% {$_.addressstring}) -join ","
    }

    $addrlist | out-file c:\somedir\addrlist.csv


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    • Proposed as answer by Jon-Alfred Smith Saturday, January 22, 2011 11:33 AM
    • Marked as answer by Gen Lin Friday, January 28, 2011 2:17 AM
    Friday, January 21, 2011 2:00 PM

All replies

  • See if this helps: http://exchangeshare.wordpress.com/2008/12/10/powershell-export-multivalued-properties/
    - Thanks, Jinesh.
    Wednesday, January 19, 2011 4:38 AM
  • You can use the below command if you are trying for a single user. This will list all the email addresses you find in the email addresses tab.

    (Get-MailContact -id juser).emailaddresses | select addressstring | export-csv C:\admin\email.csv

    Let me know if you are looking to run this for multiple users and i will write a script to do that.

    Wednesday, January 19, 2011 6:15 AM
  • Hi,

    Use below script :

    Dim strFilePath
    strFilePath = Inputbox(“Please provide a path for the CSV file”,”Provide Filename”,”*.csv”)
    Dim rootDSE, domainObject
    Set rootDSE=GetObject(“LDAP://RootDSE“)
    domainContainer = rootDSE.Get(“defaultNamingContext”)
    Set domainObject = GetObject(“LDAP://” & domainContainer)
    Set fs = CreateObject (“Scripting.FileSystemObject”)
    Set userFile = fs.CreateTextFile (strFilePath)

    ExportUsers(domainObject)

    Set oDomain = Nothing
    MsgBox “Script Completed”
    WScript.Quit

    Sub ExportUsers(oObject)
     Dim oUser
     For Each oUser in oObject
      Select Case oUser.Class
       Case “user”
        If oUser.mail <> “” then
        
         userFile.Write “,” & oUser.displayName &  “,” & oUser.sAMAccountName & “,” & oUser.userprincipalname & “,”
        On error Resume Next
         for each email in oUser.proxyAddresses
          userFile.Write email & “,”
         next
          userFile.WriteLine “”
        End if

       Case “organizationalUnit” , “container”
        If UsersinOU (oUser) then ExportUsers(oUser) End if
       
       End select
     Next

    End Sub

    Function UsersinOU (oObject)
     Dim oUser
     UsersinOU = False
      for Each oUser in oObject
       Select Case oUser.Class
        Case “organizationalUnit” , “container”
         UsersinOU = UsersinOU(oUser)
         Case “user”
         UsersinOU = True
       End select
      Next
    End Function


    Dinesh S.
    Wednesday, January 19, 2011 8:27 AM
  • I am seeking to find all email addresses from multiple users. I would really appreciate a powershell script since it will help me learn.

    Thank you

    Thursday, January 20, 2011 12:14 AM
  • Hello,

    Get-mailcontact -id juser |select-object emailaddress|export-csv c:\admin\email.csv doesn't properly export multiple email addresses. Does anyone know how I can obtain them and export to a csv?

    Thank you

    First, define "properly export".  You're exporting a multivalued property to csv. That could mean you want one address in a cell by itself, or it could mean you want all the address listed together in one cell, possibly with a delimiter between each one. 

     


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    Thursday, January 20, 2011 1:21 AM
  • I would like each value to be separated by a comma so that each address would show up in an individual cell.

    I appreciate your help.

    Robert

    Friday, January 21, 2011 1:02 AM
  • Using the source given by Jinesh, you can modify the command as below. But if you would like your values to be in separate cells then you must export the contents to TXT file and then change the extension to csv. I have tried exporting directly to CSV but it was not placing the values in individual cells

    For single user:

    Get-MailContact -id juser  | Select @{Name=’EmailAddresses’;Expression={[string]::join(",", ($_.EmailAddresses))}} | Add-Content C:\Admin\email.txt

    For All mail contacts within the organizaton:

    Get-MailContact | Select @{Name=’EmailAddresses’;Expression={[string]::join(",", ($_.EmailAddresses))}} | Add-Content C:\Admin\email.txt

    For a set of users imported from CSV (Input CSV file must have "Name" in the first cell):

    $InputUsers = Import-Csv "C:\Test.csv"

    $InputUsers | foreach-object {

    Get-MailContact $_.Name | Select @{Name=’EmailAddresses’;Expression={[string]::join(",", ($_.EmailAddresses))}} | Add-Content C:\Admin\email.txt}

     

     

    Friday, January 21, 2011 9:06 AM
  • This should create a comma separate list file of the mailcontacts names and all of their email addressses.


    $addrlist = get-mailcontact | foreach {
    @($_.name) + @($_.emailaddresses |% {$_.addressstring}) -join ","
    }

    $addrlist | out-file c:\somedir\addrlist.csv


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    • Proposed as answer by Jon-Alfred Smith Saturday, January 22, 2011 11:33 AM
    • Marked as answer by Gen Lin Friday, January 28, 2011 2:17 AM
    Friday, January 21, 2011 2:00 PM
  •  

    You can use below command to get all the SMTP address for particular Mail contact. You can also script it use for multiple email address from a file. 

    get-mailcontact <identity> | select displayName, PrimarySMTPAddress, @{Name="Emailaddresses";expression={$_.Emailaddresses | where {$_ -like "*SMTP:*"}}} | export-csv C:\admin\output.csv -Notype

    Friday, January 21, 2011 6:50 PM
  • Thanks Singh_Raj,

    How would I script this command to work with import-csv c:\admin\contacts.txt with the name of the contact in a column and Name in the first field?

    Ex:

    Name

    "April Adams"

    "Bill Bradford"

    Thank you

     

     

     

     

    Thursday, January 27, 2011 10:27 PM
  • Hi Rajitha

    Im using outlook 365, we have a group and individual addresses, i would like to export only the list of individual users to CSV file.

    I need a script and how do i ran the script?

    Thank you

    Friday, October 25, 2013 9:03 AM