Exporting multiple email addresses to CSV
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
January 18th, 2011 11:07pm
See if this helps: http://exchangeshare.wordpress.com/2008/12/10/powershell-export-multivalued-properties/- Thanks, Jinesh.
Free Windows Admin Tool Kit Click here and download it now
January 18th, 2011 11:42pm
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.
January 19th, 2011 1:19am
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 FunctionDinesh S.
Free Windows Admin Tool Kit Click here and download it now
January 19th, 2011 3:33am
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
January 19th, 2011 7:19pm
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 " "
Free Windows Admin Tool Kit Click here and download it now
January 19th, 2011 8:26pm
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
January 20th, 2011 8:07pm
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}
Free Windows Admin Tool Kit Click here and download it now
January 21st, 2011 4:12am
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 " "
January 21st, 2011 9:05am
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
Free Windows Admin Tool Kit Click here and download it now
January 21st, 2011 1:55pm
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
January 27th, 2011 5:32pm