Solved

Exporting Exchange contacts to CSV

Posted on 2014-10-07
8
248 Views
Last Modified: 2014-11-12
Hello Experts,

I am working though an issue where a user would like specific fields for all distribution group contacts exported to a CSV.

I have found a script on TechNet (http://gallery.technet.microsoft.com/office/Export-all-distribution-707c27eb) that does about half of the fields. I was able to update the script to include several new fields but seem to be hung on two of them. Can anyone assist me with getting the street address and mobile phone number to map correctly on the CSV. Currently the columns for these two fields show up blank.

Here is the script.
<#

.Requires -version 2 - Runs in Exchange Management Shell

.SYNOPSIS
.\DistributionGroupMemberReport.ps1 - It Can Display all the Distribution Group and its members on a List

Or It can Export to a CSV file


Example 1

[PS] C:\DG>.\DistributionGroupMemberReport.ps1


Distribution Group Member Report
----------------------------

1.Display in Shell

2.Export to CSV File

Choose The Task: 1

DisplayName                   Alias                         Primary SMTP streetAddress          Distriubtion Group
-----------                   -----                         --------------------          ------------------
Atlast1                       Atlast1                       Atlast1@targetexchange.in     Test1
Atlast2                       Atlast2                       Atlast2@careexchange.in       Test1
Blink                         Blink                         Blink@targetexchange.in       Test1
blink1                        blink1                        blink1@targetexchange.in      Test1
User2                         User2                         User2@careexchange.in         Test11
User3                         User3                         User3@careexchange.in         Test11
User4                         User4                         User4@careexchange.in         Test11
WithClient                    WithClient                    WithClient@careexchange.in    Test11
Blink                         Blink                         Blink@targetexchange.in       Test11
blink1                        blink1                        blink1@targetexchange.in      Test11

Example 2

[PS] C:\DG>.\DistributionGroupMemberReport.ps1


Distribution Group Member Report
----------------------------

1.Display in Shell

2.Export to CSV File

Choose The Task: 2
Enter the Path of CSV file (Eg. C:\DG.csv): C:\DGmembers.csv

.Author
Written By: Satheshwaran Manoharan

Change Log
V1.0, 11/10/2012 - Initial version

Change Log
V1.1, 02/07/2014 - Added "Enter the Distribution Group name with Wild Card"

Change Log
V1.2, 19/07/2014 - Added "Recipient OU,Distribution Group Primary SMTP streetAddress,Distribution Group Managers,Distribution Group OU"
V1.2.1, 19/07/2014 - Added "Option- Enter the Distribution Group name with Wild Card (Display)"
V1.2.2, 19/07/2014 - Added "Fixed "Hashtable-to-Object conversion is not supported in restricted language mode or a Data section"

V1.3,05/08/2014 - Hashtable-to-Object conversion is not supported - Fixed 
#>

Write-host "

Distribution Group Member Report
----------------------------

1.Display in Exchange Management Shell

2.Export to CSV File

3.Enter the Distribution Group name with Wild Card (Export)

4.Enter the Distribution Group name with Wild Card (Display)

Dynamic Distribution Group Member Report
----------------------------

5.Display in Exchange Management Shell

6.Export to CSV File

7.Enter the Dynamic Distribution Group name with Wild Card (Export)

8.Enter the Dynamic Group name with Wild Card (Display)"-ForeGround "Cyan"

#----------------
# Script
#----------------

Write-Host "               "

$number = Read-Host "Choose The Task"
$output = @()
switch ($number) 
{

1 {

$AllDG = Get-DistributionGroup -resultsize unlimited

Foreach($dg in $allDg)

{

$Members = Get-DistributionGroupMember $Dg.name -resultsize unlimited

$Total = $Members.Count

$RemoveNull = $Total-1

For($i=0;$i -le $RemoveNull;$i++)

{

$userObj = New-Object PSObject

$userObj | Add-Member NoteProperty -Name "Alias" -Value $members[$i].Alias
$userObj | Add-Member NoteProperty -Name "Department" -Value $members[$i].Department
$userObj | Add-Member NoteProperty -Name "Title" -Value $members[$i].Title
$userObj | Add-Member NoteProperty -Name "Phone" -Value $members[$i].Phone
$userObj | Add-Member NoteProperty -Name "Mobile" -Value $members[$i].Mobile
$userObj | Add-Member NoteProperty -Name "streetAddress" -Value $members[$i].streetAddress
$userObj | Add-Member NoteProperty -Name "city" -Value $members[$i].city
$userObj | Add-Member NoteProperty -Name "StateOrProvince" -Value $members[$i].StateOrProvince
$userObj | Add-Member NoteProperty -Name "postalcode" -Value $members[$i].postalcode
$userObj | Add-Member NoteProperty -Name "Location" -Value $members[$i].Location
$userObj | Add-Member NoteProperty -Name "First Name" -Value $members[$i].firstname
$userObj | Add-Member NoteProperty -Name "Last Name" -Value $members[$i].lastname
$userObj | Add-Member NoteProperty -Name "Primary SMTP streetAddress" -Value $members[$i].PrimarySmtpstreetAddress
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name


Write-Output $Userobj

}

}

;Break}

2 {

$CSVfile = Read-Host "Enter the Path of CSV file (Eg. C:\DG.csv)" 

$AllDG = Get-DistributionGroup -resultsize unlimited

Foreach($dg in $allDg)

{

$Members = Get-DistributionGroupMember $Dg.name -resultsize unlimited

$Total = $Members.Count

$RemoveNull = $Total-1

For($i=0;$i -le $RemoveNull;$i++)

{
$managers = $Dg | Select @{Name='DistributionGroupManagers';Expression={[string]::join(";", ($_.Managedby))}}

$userObj = New-Object PSObject

$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $members[$i].Name
$userObj | Add-Member NoteProperty -Name "Department" -Value $members[$i].Department
$userObj | Add-Member NoteProperty -Name "Title" -Value $members[$i].Title
$userObj | Add-Member NoteProperty -Name "Phone" -Value $members[$i].Phone
$userObj | Add-Member NoteProperty -Name "Mobile" -Value $members[$i].Mobile
$userObj | Add-Member NoteProperty -Name "streetAddress" -Value $members[$i].streetAddress
$userObj | Add-Member NoteProperty -Name "city" -Value $members[$i].city
$userObj | Add-Member NoteProperty -Name "StateOrProvince" -Value $members[$i].StateOrProvince
$userObj | Add-Member NoteProperty -Name "postalcode" -Value $members[$i].postalcode
$userObj | Add-Member NoteProperty -Name "Location" -Value $members[$i].Location
$userObj | Add-Member NoteProperty -Name "Last Name" -Value $members[$i].lastname
$userObj | Add-Member NoteProperty -Name "First Name" -Value $members[$i].Firstname
$userObj | Add-Member NoteProperty -Name "Alias" -Value $members[$i].Alias
$userObj | Add-Member NoteProperty -Name "RecipientType" -Value $members[$i].RecipientType
$userObj | Add-Member NoteProperty -Name "Recipient OU" -Value $members[$i].OrganizationalUnit
$userObj | Add-Member NoteProperty -Name "Primary SMTP streetAddress" -Value $members[$i].PrimarySmtpstreetAddress
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name
$userObj | Add-Member NoteProperty -Name "Distribution Group Primary SMTP streetAddress" -Value $DG.PrimarySmtpstreetAddress
$userObj | Add-Member NoteProperty -Name "Distribution Group Managers" -Value $managers.DistributionGroupManagers
$userObj | Add-Member NoteProperty -Name "Distribution Group OU" -Value $DG.OrganizationalUnit
$userObj | Add-Member NoteProperty -Name "Distribution Group Type" -Value $DG.GroupType
$userObj | Add-Member NoteProperty -Name "Distribution Group Recipient Type" -Value $DG.RecipientType


$output += $UserObj  

}

$output | Export-csv -Path $CSVfile -NoTypeInformation

}



;Break}

3 {

$CSVfile = Read-Host "Enter the Path of CSV file (Eg. C:\DG.csv)" 

$Dgname = Read-Host "Enter the DG name or Range (Eg. DGname , DG*,*DG)"

$AllDG = Get-DistributionGroup $Dgname -resultsize unlimited

Foreach($dg in $allDg)

{

$Members = Get-DistributionGroupMember $Dg.name -resultsize unlimited

$Total = $Members.Count

$RemoveNull = $Total-1

For($i=0;$i -le $RemoveNull;$i++)

{

$managers = $Dg | Select @{Name='DistributionGroupManagers';Expression={[string]::join(";", ($_.Managedby))}}

$userObj = New-Object PSObject


$userObj | Add-Member NoteProperty -Name "Alias" -Value $members[$i].Alias
$userObj | Add-Member NoteProperty -Name "Department" -Value $members[$i].Department
$userObj | Add-Member NoteProperty -Name "Title" -Value $members[$i].Title
$userObj | Add-Member NoteProperty -Name "Phone" -Value $members[$i].Phone
$userObj | Add-Member NoteProperty -Name "Mobile" -Value $members[$i].Mobile
$userObj | Add-Member NoteProperty -Name "streetAddress" -Value $members[$i].streetAddress
$userObj | Add-Member NoteProperty -Name "city" -Value $members[$i].city
$userObj | Add-Member NoteProperty -Name "StateOrProvince" -Value $members[$i].StateOrProvince
$userObj | Add-Member NoteProperty -Name "postalcode" -Value $members[$i].postalcode
$userObj | Add-Member NoteProperty -Name "Location" -Value $members[$i].Location
$userObj | Add-Member NoteProperty -Name "RecipientType" -Value $members[$i].RecipientType
$userObj | Add-Member NoteProperty -Name "Last Name" -Value $members[$i].lastname
$userObj | Add-Member NoteProperty -Name "First Name" -Value $members[$i].Firstname
$userObj | Add-Member NoteProperty -Name "Recipient OU" -Value $members[$i].OrganizationalUnit
$userObj | Add-Member NoteProperty -Name "Primary SMTP streetAddress" -Value $members[$i].PrimarySmtpstreetAddress
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name
$userObj | Add-Member NoteProperty -Name "Distribution Group Primary SMTP streetAddress" -Value $DG.PrimarySmtpstreetAddress
$userObj | Add-Member NoteProperty -Name "Distribution Group Managers" -Value $managers.DistributionGroupManagers
$userObj | Add-Member NoteProperty -Name "Distribution Group OU" -Value $DG.OrganizationalUnit
$userObj | Add-Member NoteProperty -Name "Distribution Group Type" -Value $DG.GroupType
$userObj | Add-Member NoteProperty -Name "Distribution Group Recipient Type" -Value $DG.RecipientType

$output += $UserObj   

}

$output | Export-csv -Path $CSVfile -NoTypeInformation

}

;Break}

4 {

$Dgname = Read-Host "Enter the DG name or Range (Eg. DGname , DG*,*DG)"

$AllDG = Get-DistributionGroup $Dgname -resultsize unlimited

Foreach($dg in $allDg)

{

$Members = Get-DistributionGroupMember $Dg.name -resultsize unlimited

$Total = $Members.Count

$RemoveNull = $Total-1

For($i=0;$i -le $RemoveNull;$i++)

{

$userObj = New-Object PSObject

$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $members[$i].Name
$userObj | Add-Member NoteProperty -Name "Department" -Value $members[$i].Department
$userObj | Add-Member NoteProperty -Name "Title" -Value $members[$i].Title
$userObj | Add-Member NoteProperty -Name "Phone" -Value $members[$i].Phone
$userObj | Add-Member NoteProperty -Name "Mobile" -Value $members[$i].Mobile
$userObj | Add-Member NoteProperty -Name "streetAddress" -Value $members[$i].streetAddress
$userObj | Add-Member NoteProperty -Name "city" -Value $members[$i].city
$userObj | Add-Member NoteProperty -Name "StateOrProvince" -Value $members[$i].StateOrProvince
$userObj | Add-Member NoteProperty -Name "postalcode" -Value $members[$i].postalcode
$userObj | Add-Member NoteProperty -Name "Location" -Value $members[$i].Location
$userObj | Add-Member NoteProperty -Name "First Name" -Value $members[$i].firstname
$userObj | Add-Member NoteProperty -Name "Last Name" -Value $members[$i].lastname
$userObj | Add-Member NoteProperty -Name "Alias" -Value $members[$i].Alias
$userObj | Add-Member NoteProperty -Name "Primary SMTP streetAddress" -Value $members[$i].PrimarySmtpstreetAddress
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name


Write-Output $Userobj

}

}

;Break}


5 {

$AllDG = Get-DynamicDistributionGroup -resultsize unlimited

Foreach($dg in $allDg)

{

$Members = Get-Recipient -RecipientPreviewFilter $dg.RecipientFilter -resultsize unlimited

$Total = $Members.Count

$RemoveNull = $Total-1

For($i=0;$i -le $RemoveNull;$i++)

{

$userObj = New-Object PSObject

$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $members[$i].Name
$userObj | Add-Member NoteProperty -Name "Department" -Value $members[$i].Department
$userObj | Add-Member NoteProperty -Name "Title" -Value $members[$i].Title
$userObj | Add-Member NoteProperty -Name "Phone" -Value $members[$i].Phone
$userObj | Add-Member NoteProperty -Name "Mobile" -Value $members[$i].Mobile
$userObj | Add-Member NoteProperty -Name "streetAddress" -Value $members[$i].streetAddress
$userObj | Add-Member NoteProperty -Name "city" -Value $members[$i].city
$userObj | Add-Member NoteProperty -Name "StateOrProvince" -Value $members[$i].StateOrProvince
$userObj | Add-Member NoteProperty -Name "postalcode" -Value $members[$i].postalcode
$userObj | Add-Member NoteProperty -Name "Location" -Value $members[$i].Location
$userObj | Add-Member NoteProperty -Name "First Name" -Value $members[$i].firstname
$userObj | Add-Member NoteProperty -Name "Last Name" -Value $members[$i].lastname
$userObj | Add-Member NoteProperty -Name "Alias" -Value $members[$i].Alias
$userObj | Add-Member NoteProperty -Name "Primary SMTP streetAddress" -Value $members[$i].PrimarySmtpstreetAddress
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name


Write-Output $Userobj

}

}

;Break}

6 {

$CSVfile = Read-Host "Enter the Path of CSV file (Eg. C:\DYDG.csv)" 

$AllDG = Get-DynamicDistributionGroup -resultsize unlimited

Foreach($dg in $allDg)

{

$Members = Get-Recipient -RecipientPreviewFilter $dg.RecipientFilter -resultsize unlimited

$Total = $Members.Count

$RemoveNull = $Total-1

For($i=0;$i -le $RemoveNull;$i++)

{
$managers = $Dg | Select @{Name='DistributionGroupManagers';Expression={[string]::join(";", ($_.Managedby))}}

$userObj = New-Object PSObject

$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $members[$i].Name
$userObj | Add-Member NoteProperty -Name "Department" -Value $members[$i].Department
$userObj | Add-Member NoteProperty -Name "Title" -Value $members[$i].Title
$userObj | Add-Member NoteProperty -Name "Phone" -Value $members[$i].Phone
$userObj | Add-Member NoteProperty -Name "Mobile" -Value $members[$i].Mobile
$userObj | Add-Member NoteProperty -Name "streetAddress" -Value $members[$i].streetAddress
$userObj | Add-Member NoteProperty -Name "city" -Value $members[$i].city
$userObj | Add-Member NoteProperty -Name "StateOrProvince" -Value $members[$i].StateOrProvince
$userObj | Add-Member NoteProperty -Name "postalcode" -Value $members[$i].postalcode
$userObj | Add-Member NoteProperty -Name "Location" -Value $members[$i].Location
$userObj | Add-Member NoteProperty -Name "Alias" -Value $members[$i].Alias
$userObj | Add-Member NoteProperty -Name "Last Name" -Value $members[$i].lastname
$userObj | Add-Member NoteProperty -Name "First Name" -Value $members[$i].Firstname
$userObj | Add-Member NoteProperty -Name "RecipientType" -Value $members[$i].RecipientType
$userObj | Add-Member NoteProperty -Name "Recipient OU" -Value $members[$i].OrganizationalUnit
$userObj | Add-Member NoteProperty -Name "Primary SMTP streetAddress" -Value $members[$i].PrimarySmtpstreetAddress
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name
$userObj | Add-Member NoteProperty -Name "Distribution Group Primary SMTP streetAddress" -Value $DG.PrimarySmtpstreetAddress
$userObj | Add-Member NoteProperty -Name "Distribution Group Managers" -Value $managers.DistributionGroupManagers
$userObj | Add-Member NoteProperty -Name "Distribution Group OU" -Value $DG.OrganizationalUnit
$userObj | Add-Member NoteProperty -Name "Distribution Group Type" -Value $DG.RecipientType
$userObj | Add-Member NoteProperty -Name "Distribution Group Recipient Type" -Value $DG.RecipientType


$output += $UserObj  

}

$output | Export-csv -Path $CSVfile -NoTypeInformation

}

;Break}


7 {

$CSVfile = Read-Host "Enter the Path of CSV file (Eg. C:\DYDG.csv)" 

$Dgname = Read-Host "Enter the DG name or Range (Eg. DynmicDGname , Dy*,*Dy)"

$AllDG = Get-DynamicDistributionGroup $Dgname -resultsize unlimited

Foreach($dg in $allDg)

{

$Members = Get-Recipient -RecipientPreviewFilter $dg.RecipientFilter -resultsize unlimited

$Total = $Members.Count

$RemoveNull = $Total-1

For($i=0;$i -le $RemoveNull;$i++)

{

$managers = $Dg | Select @{Name='DistributionGroupManagers';Expression={[string]::join(";", ($_.Managedby))}}

$userObj = New-Object PSObject

$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $members[$i].Name
$userObj | Add-Member NoteProperty -Name "Department" -Value $members[$i].Department
$userObj | Add-Member NoteProperty -Name "Title" -Value $members[$i].Title
$userObj | Add-Member NoteProperty -Name "Phone" -Value $members[$i].Phone
$userObj | Add-Member NoteProperty -Name "Mobile" -Value $members[$i].Mobile
$userObj | Add-Member NoteProperty -Name "streetAddress" -Value $members[$i].streetAddress
$userObj | Add-Member NoteProperty -Name "city" -Value $members[$i].city
$userObj | Add-Member NoteProperty -Name "StateOrProvince" -Value $members[$i].StateOrProvince
$userObj | Add-Member NoteProperty -Name "postalcode" -Value $members[$i].postalcode
$userObj | Add-Member NoteProperty -Name "Location" -Value $members[$i].Location
$userObj | Add-Member NoteProperty -Name "Alias" -Value $members[$i].Alias
$userObj | Add-Member NoteProperty -Name "Last Name" -Value $members[$i].lastname
$userObj | Add-Member NoteProperty -Name "First Name" -Value $members[$i].Firstname
$userObj | Add-Member NoteProperty -Name "RecipientType" -Value $members[$i].RecipientType
$userObj | Add-Member NoteProperty -Name "Recipient OU" -Value $members[$i].OrganizationalUnit
$userObj | Add-Member NoteProperty -Name "Primary SMTP streetAddress" -Value $members[$i].PrimarySmtpstreetAddress
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name
$userObj | Add-Member NoteProperty -Name "Distribution Group Primary SMTP streetAddress" -Value $DG.PrimarySmtpstreetAddress
$userObj | Add-Member NoteProperty -Name "Distribution Group Managers" -Value $managers.DistributionGroupManagers
$userObj | Add-Member NoteProperty -Name "Distribution Group OU" -Value $DG.OrganizationalUnit
$userObj | Add-Member NoteProperty -Name "Distribution Group Type" -Value $DG.RecipientType
$userObj | Add-Member NoteProperty -Name "Distribution Group Recipient Type" -Value $DG.RecipientType

$output += $UserObj   

}

$output | Export-csv -Path $CSVfile -NoTypeInformation

}


;Break}

8 {

$Dgname = Read-Host "Enter the Dynamic DG name or Range (Eg. DynamicDGname , DG*,*DG)"

$AllDG = Get-DynamicDistributionGroup $Dgname -resultsize unlimited

Foreach($dg in $allDg)

{

$Members = Get-Recipient -RecipientPreviewFilter $dg.RecipientFilter -resultsize unlimited

$Total = $Members.Count

$RemoveNull = $Total-1

For($i=0;$i -le $RemoveNull;$i++)

{

$userObj = New-Object PSObject

$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $members[$i].Name
$userObj | Add-Member NoteProperty -Name "Department" -Value $members[$i].Department
$userObj | Add-Member NoteProperty -Name "Title" -Value $members[$i].Title
$userObj | Add-Member NoteProperty -Name "Phone" -Value $members[$i].Phone
$userObj | Add-Member NoteProperty -Name "Mobile" -Value $members[$i].Mobile
$userObj | Add-Member NoteProperty -Name "streetAddress" -Value $members[$i].streetAddress
$userObj | Add-Member NoteProperty -Name "city" -Value $members[$i].city
$userObj | Add-Member NoteProperty -Name "StateOrProvince" -Value $members[$i].StateOrProvince
$userObj | Add-Member NoteProperty -Name "postalcode" -Value $members[$i].postalcode
$userObj | Add-Member NoteProperty -Name "Location" -Value $members[$i].Location
$userObj | Add-Member NoteProperty -Name "First Name" -Value $members[$i].firstname
$userObj | Add-Member NoteProperty -Name "Last Name" -Value $members[$i].lastname
$userObj | Add-Member NoteProperty -Name "Alias" -Value $members[$i].Alias
$userObj | Add-Member NoteProperty -Name "Primary SMTP streetAddress" -Value $members[$i].PrimarySmtpstreetAddress
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name


Write-Output $Userobj

}

}

;Break}

Default {Write-Host "No matches found , Enter Options 1 or 2" -ForeGround "red"}

}

Open in new window

0
Comment
Question by:PSC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 16

Expert Comment

by:Rajitha Chimmani
ID: 40366695
I have not gone through entire script but just updated the mobile phone and street address lines of code. You need to query AD properties to get these values. The script is trying to get them from Get-Distributiongroupmember. I guess there are several other values which are AD values.


<#

.Requires -version 2 - Runs in Exchange Management Shell

.SYNOPSIS
.\DistributionGroupMemberReport.ps1 - It Can Display all the Distribution Group and its members on a List

Or It can Export to a CSV file


Example 1

[PS] C:\DG>.\DistributionGroupMemberReport.ps1


Distribution Group Member Report
----------------------------

1.Display in Shell

2.Export to CSV File

Choose The Task: 1

DisplayName                   Alias                         Primary SMTP streetAddress          Distriubtion Group
-----------                   -----                         --------------------          ------------------
Atlast1                       Atlast1                       Atlast1@targetexchange.in     Test1
Atlast2                       Atlast2                       Atlast2@careexchange.in       Test1
Blink                         Blink                         Blink@targetexchange.in       Test1
blink1                        blink1                        blink1@targetexchange.in      Test1
User2                         User2                         User2@careexchange.in         Test11
User3                         User3                         User3@careexchange.in         Test11
User4                         User4                         User4@careexchange.in         Test11
WithClient                    WithClient                    WithClient@careexchange.in    Test11
Blink                         Blink                         Blink@targetexchange.in       Test11
blink1                        blink1                        blink1@targetexchange.in      Test11

Example 2

[PS] C:\DG>.\DistributionGroupMemberReport.ps1


Distribution Group Member Report
----------------------------

1.Display in Shell

2.Export to CSV File

Choose The Task: 2
Enter the Path of CSV file (Eg. C:\DG.csv): C:\DGmembers.csv

.Author
Written By: Satheshwaran Manoharan

Change Log
V1.0, 11/10/2012 - Initial version

Change Log
V1.1, 02/07/2014 - Added "Enter the Distribution Group name with Wild Card"

Change Log
V1.2, 19/07/2014 - Added "Recipient OU,Distribution Group Primary SMTP streetAddress,Distribution Group Managers,Distribution Group OU"
V1.2.1, 19/07/2014 - Added "Option- Enter the Distribution Group name with Wild Card (Display)"
V1.2.2, 19/07/2014 - Added "Fixed "Hashtable-to-Object conversion is not supported in restricted language mode or a Data section"

V1.3,05/08/2014 - Hashtable-to-Object conversion is not supported - Fixed 
#>

Write-host "

Distribution Group Member Report
----------------------------

1.Display in Exchange Management Shell

2.Export to CSV File

3.Enter the Distribution Group name with Wild Card (Export)

4.Enter the Distribution Group name with Wild Card (Display)

Dynamic Distribution Group Member Report
----------------------------

5.Display in Exchange Management Shell

6.Export to CSV File

7.Enter the Dynamic Distribution Group name with Wild Card (Export)

8.Enter the Dynamic Group name with Wild Card (Display)"-ForeGround "Cyan"

#----------------
# Script
#----------------

Write-Host "               "

$number = Read-Host "Choose The Task"
$output = @()
switch ($number) 
{

1 {

$AllDG = Get-DistributionGroup -resultsize unlimited

Foreach($dg in $allDg)

{

$Members = Get-DistributionGroupMember $Dg.name -resultsize unlimited

$Total = $Members.Count

$RemoveNull = $Total-1

For($i=0;$i -le $RemoveNull;$i++)

{
$ADProps = Get-User $Members[$i].Samaccountname

$userObj = New-Object PSObject

$userObj | Add-Member NoteProperty -Name "Alias" -Value $members[$i].Alias
$userObj | Add-Member NoteProperty -Name "Department" -Value $members[$i].Department
$userObj | Add-Member NoteProperty -Name "Title" -Value $members[$i].Title
$userObj | Add-Member NoteProperty -Name "Phone" -Value $members[$i].Phone
$userObj | Add-Member NoteProperty -Name "Mobile" -Value $ADProps.MobilePhone
$userObj | Add-Member NoteProperty -Name "streetAddress" -Value $ADProps.streetAddress
$userObj | Add-Member NoteProperty -Name "city" -Value $members[$i].city
$userObj | Add-Member NoteProperty -Name "StateOrProvince" -Value $members[$i].StateOrProvince
$userObj | Add-Member NoteProperty -Name "postalcode" -Value $members[$i].postalcode
$userObj | Add-Member NoteProperty -Name "Location" -Value $members[$i].Location
$userObj | Add-Member NoteProperty -Name "First Name" -Value $members[$i].firstname
$userObj | Add-Member NoteProperty -Name "Last Name" -Value $members[$i].lastname
$userObj | Add-Member NoteProperty -Name "Primary SMTP streetAddress" -Value $members[$i].PrimarySmtpstreetAddress
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name


Write-Output $Userobj

}

}

;Break}

2 {

$CSVfile = Read-Host "Enter the Path of CSV file (Eg. C:\DG.csv)" 

$AllDG = Get-DistributionGroup -resultsize unlimited

Foreach($dg in $allDg)

{

$Members = Get-DistributionGroupMember $Dg.name -resultsize unlimited

$Total = $Members.Count

$RemoveNull = $Total-1

For($i=0;$i -le $RemoveNull;$i++)

{
$managers = $Dg | Select @{Name='DistributionGroupManagers';Expression={[string]::join(";", ($_.Managedby))}}
$ADProps = Get-User $Members[$i].Samaccountname

$userObj = New-Object PSObject

$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $members[$i].Name
$userObj | Add-Member NoteProperty -Name "Department" -Value $members[$i].Department
$userObj | Add-Member NoteProperty -Name "Title" -Value $members[$i].Title
$userObj | Add-Member NoteProperty -Name "Phone" -Value $members[$i].Phone
$userObj | Add-Member NoteProperty -Name "Mobile" -Value $ADProps.MobilePhone
$userObj | Add-Member NoteProperty -Name "streetAddress" -Value $ADProps.streetAddress
$userObj | Add-Member NoteProperty -Name "city" -Value $members[$i].city
$userObj | Add-Member NoteProperty -Name "StateOrProvince" -Value $members[$i].StateOrProvince
$userObj | Add-Member NoteProperty -Name "postalcode" -Value $members[$i].postalcode
$userObj | Add-Member NoteProperty -Name "Location" -Value $members[$i].Location
$userObj | Add-Member NoteProperty -Name "Last Name" -Value $members[$i].lastname
$userObj | Add-Member NoteProperty -Name "First Name" -Value $members[$i].Firstname
$userObj | Add-Member NoteProperty -Name "Alias" -Value $members[$i].Alias
$userObj | Add-Member NoteProperty -Name "RecipientType" -Value $members[$i].RecipientType
$userObj | Add-Member NoteProperty -Name "Recipient OU" -Value $members[$i].OrganizationalUnit
$userObj | Add-Member NoteProperty -Name "Primary SMTP streetAddress" -Value $members[$i].PrimarySmtpstreetAddress
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name
$userObj | Add-Member NoteProperty -Name "Distribution Group Primary SMTP streetAddress" -Value $DG.PrimarySmtpstreetAddress
$userObj | Add-Member NoteProperty -Name "Distribution Group Managers" -Value $managers.DistributionGroupManagers
$userObj | Add-Member NoteProperty -Name "Distribution Group OU" -Value $DG.OrganizationalUnit
$userObj | Add-Member NoteProperty -Name "Distribution Group Type" -Value $DG.GroupType
$userObj | Add-Member NoteProperty -Name "Distribution Group Recipient Type" -Value $DG.RecipientType


$output += $UserObj  

}

$output | Export-csv -Path $CSVfile -NoTypeInformation

}



;Break}

3 {

$CSVfile = Read-Host "Enter the Path of CSV file (Eg. C:\DG.csv)" 

$Dgname = Read-Host "Enter the DG name or Range (Eg. DGname , DG*,*DG)"

$AllDG = Get-DistributionGroup $Dgname -resultsize unlimited

Foreach($dg in $allDg)

{

$Members = Get-DistributionGroupMember $Dg.name -resultsize unlimited

$Total = $Members.Count

$RemoveNull = $Total-1

For($i=0;$i -le $RemoveNull;$i++)

{

$managers = $Dg | Select @{Name='DistributionGroupManagers';Expression={[string]::join(";", ($_.Managedby))}}
$ADProps = Get-User $Members[$i].Samaccountname

$userObj = New-Object PSObject


$userObj | Add-Member NoteProperty -Name "Alias" -Value $members[$i].Alias
$userObj | Add-Member NoteProperty -Name "Department" -Value $members[$i].Department
$userObj | Add-Member NoteProperty -Name "Title" -Value $members[$i].Title
$userObj | Add-Member NoteProperty -Name "Phone" -Value $members[$i].Phone
$userObj | Add-Member NoteProperty -Name "Mobile" -Value $ADProps.MobilePhone
$userObj | Add-Member NoteProperty -Name "streetAddress" -Value $ADProps.streetAddress
$userObj | Add-Member NoteProperty -Name "city" -Value $members[$i].city
$userObj | Add-Member NoteProperty -Name "StateOrProvince" -Value $members[$i].StateOrProvince
$userObj | Add-Member NoteProperty -Name "postalcode" -Value $members[$i].postalcode
$userObj | Add-Member NoteProperty -Name "Location" -Value $members[$i].Location
$userObj | Add-Member NoteProperty -Name "RecipientType" -Value $members[$i].RecipientType
$userObj | Add-Member NoteProperty -Name "Last Name" -Value $members[$i].lastname
$userObj | Add-Member NoteProperty -Name "First Name" -Value $members[$i].Firstname
$userObj | Add-Member NoteProperty -Name "Recipient OU" -Value $members[$i].OrganizationalUnit
$userObj | Add-Member NoteProperty -Name "Primary SMTP streetAddress" -Value $members[$i].PrimarySmtpstreetAddress
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name
$userObj | Add-Member NoteProperty -Name "Distribution Group Primary SMTP streetAddress" -Value $DG.PrimarySmtpstreetAddress
$userObj | Add-Member NoteProperty -Name "Distribution Group Managers" -Value $managers.DistributionGroupManagers
$userObj | Add-Member NoteProperty -Name "Distribution Group OU" -Value $DG.OrganizationalUnit
$userObj | Add-Member NoteProperty -Name "Distribution Group Type" -Value $DG.GroupType
$userObj | Add-Member NoteProperty -Name "Distribution Group Recipient Type" -Value $DG.RecipientType

$output += $UserObj   

}

$output | Export-csv -Path $CSVfile -NoTypeInformation

}

;Break}

4 {

$Dgname = Read-Host "Enter the DG name or Range (Eg. DGname , DG*,*DG)"

$AllDG = Get-DistributionGroup $Dgname -resultsize unlimited

Foreach($dg in $allDg)

{

$Members = Get-DistributionGroupMember $Dg.name -resultsize unlimited

$Total = $Members.Count

$RemoveNull = $Total-1

For($i=0;$i -le $RemoveNull;$i++)

{
$ADProps = Get-User $Members[$i].Samaccountname
$userObj = New-Object PSObject

$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $members[$i].Name
$userObj | Add-Member NoteProperty -Name "Department" -Value $members[$i].Department
$userObj | Add-Member NoteProperty -Name "Title" -Value $members[$i].Title
$userObj | Add-Member NoteProperty -Name "Phone" -Value $members[$i].Phone
$userObj | Add-Member NoteProperty -Name "Mobile" -Value $ADProps.MobilePhone
$userObj | Add-Member NoteProperty -Name "streetAddress" -Value $ADProps.streetAddress
$userObj | Add-Member NoteProperty -Name "city" -Value $members[$i].city
$userObj | Add-Member NoteProperty -Name "StateOrProvince" -Value $members[$i].StateOrProvince
$userObj | Add-Member NoteProperty -Name "postalcode" -Value $members[$i].postalcode
$userObj | Add-Member NoteProperty -Name "Location" -Value $members[$i].Location
$userObj | Add-Member NoteProperty -Name "First Name" -Value $members[$i].firstname
$userObj | Add-Member NoteProperty -Name "Last Name" -Value $members[$i].lastname
$userObj | Add-Member NoteProperty -Name "Alias" -Value $members[$i].Alias
$userObj | Add-Member NoteProperty -Name "Primary SMTP streetAddress" -Value $members[$i].PrimarySmtpstreetAddress
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name


Write-Output $Userobj

}

}

;Break}


5 {

$AllDG = Get-DynamicDistributionGroup -resultsize unlimited

Foreach($dg in $allDg)

{

$Members = Get-Recipient -RecipientPreviewFilter $dg.RecipientFilter -resultsize unlimited

$Total = $Members.Count

$RemoveNull = $Total-1

For($i=0;$i -le $RemoveNull;$i++)

{
$ADProps = Get-User $Members[$i].Samaccountname
$userObj = New-Object PSObject

$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $members[$i].Name
$userObj | Add-Member NoteProperty -Name "Department" -Value $members[$i].Department
$userObj | Add-Member NoteProperty -Name "Title" -Value $members[$i].Title
$userObj | Add-Member NoteProperty -Name "Phone" -Value $members[$i].Phone
$userObj | Add-Member NoteProperty -Name "Mobile" -Value $ADProps.MobilePhone
$userObj | Add-Member NoteProperty -Name "streetAddress" -Value $ADProps.streetAddress
$userObj | Add-Member NoteProperty -Name "city" -Value $members[$i].city
$userObj | Add-Member NoteProperty -Name "StateOrProvince" -Value $members[$i].StateOrProvince
$userObj | Add-Member NoteProperty -Name "postalcode" -Value $members[$i].postalcode
$userObj | Add-Member NoteProperty -Name "Location" -Value $members[$i].Location
$userObj | Add-Member NoteProperty -Name "First Name" -Value $members[$i].firstname
$userObj | Add-Member NoteProperty -Name "Last Name" -Value $members[$i].lastname
$userObj | Add-Member NoteProperty -Name "Alias" -Value $members[$i].Alias
$userObj | Add-Member NoteProperty -Name "Primary SMTP streetAddress" -Value $members[$i].PrimarySmtpstreetAddress
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name


Write-Output $Userobj

}

}

;Break}

6 {

$CSVfile = Read-Host "Enter the Path of CSV file (Eg. C:\DYDG.csv)" 

$AllDG = Get-DynamicDistributionGroup -resultsize unlimited

Foreach($dg in $allDg)

{

$Members = Get-Recipient -RecipientPreviewFilter $dg.RecipientFilter -resultsize unlimited

$Total = $Members.Count

$RemoveNull = $Total-1

For($i=0;$i -le $RemoveNull;$i++)

{
$managers = $Dg | Select @{Name='DistributionGroupManagers';Expression={[string]::join(";", ($_.Managedby))}}
$ADProps = Get-User $Members[$i].Samaccountname

$userObj = New-Object PSObject

$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $members[$i].Name
$userObj | Add-Member NoteProperty -Name "Department" -Value $members[$i].Department
$userObj | Add-Member NoteProperty -Name "Title" -Value $members[$i].Title
$userObj | Add-Member NoteProperty -Name "Phone" -Value $members[$i].Phone
$userObj | Add-Member NoteProperty -Name "Mobile" -Value $ADProps.MobilePhone
$userObj | Add-Member NoteProperty -Name "streetAddress" -Value $ADProps.streetAddress
$userObj | Add-Member NoteProperty -Name "city" -Value $members[$i].city
$userObj | Add-Member NoteProperty -Name "StateOrProvince" -Value $members[$i].StateOrProvince
$userObj | Add-Member NoteProperty -Name "postalcode" -Value $members[$i].postalcode
$userObj | Add-Member NoteProperty -Name "Location" -Value $members[$i].Location
$userObj | Add-Member NoteProperty -Name "Alias" -Value $members[$i].Alias
$userObj | Add-Member NoteProperty -Name "Last Name" -Value $members[$i].lastname
$userObj | Add-Member NoteProperty -Name "First Name" -Value $members[$i].Firstname
$userObj | Add-Member NoteProperty -Name "RecipientType" -Value $members[$i].RecipientType
$userObj | Add-Member NoteProperty -Name "Recipient OU" -Value $members[$i].OrganizationalUnit
$userObj | Add-Member NoteProperty -Name "Primary SMTP streetAddress" -Value $members[$i].PrimarySmtpstreetAddress
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name
$userObj | Add-Member NoteProperty -Name "Distribution Group Primary SMTP streetAddress" -Value $DG.PrimarySmtpstreetAddress
$userObj | Add-Member NoteProperty -Name "Distribution Group Managers" -Value $managers.DistributionGroupManagers
$userObj | Add-Member NoteProperty -Name "Distribution Group OU" -Value $DG.OrganizationalUnit
$userObj | Add-Member NoteProperty -Name "Distribution Group Type" -Value $DG.RecipientType
$userObj | Add-Member NoteProperty -Name "Distribution Group Recipient Type" -Value $DG.RecipientType


$output += $UserObj  

}

$output | Export-csv -Path $CSVfile -NoTypeInformation

}

;Break}


7 {

$CSVfile = Read-Host "Enter the Path of CSV file (Eg. C:\DYDG.csv)" 

$Dgname = Read-Host "Enter the DG name or Range (Eg. DynmicDGname , Dy*,*Dy)"

$AllDG = Get-DynamicDistributionGroup $Dgname -resultsize unlimited

Foreach($dg in $allDg)

{

$Members = Get-Recipient -RecipientPreviewFilter $dg.RecipientFilter -resultsize unlimited

$Total = $Members.Count

$RemoveNull = $Total-1

For($i=0;$i -le $RemoveNull;$i++)

{

$managers = $Dg | Select @{Name='DistributionGroupManagers';Expression={[string]::join(";", ($_.Managedby))}}
$ADProps = Get-User $Members[$i].Samaccountname

$userObj = New-Object PSObject

$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $members[$i].Name
$userObj | Add-Member NoteProperty -Name "Department" -Value $members[$i].Department
$userObj | Add-Member NoteProperty -Name "Title" -Value $members[$i].Title
$userObj | Add-Member NoteProperty -Name "Phone" -Value $members[$i].Phone
$userObj | Add-Member NoteProperty -Name "Mobile" -Value $ADProps.MobilePhone
$userObj | Add-Member NoteProperty -Name "streetAddress" -Value $ADProps.streetAddress
$userObj | Add-Member NoteProperty -Name "city" -Value $members[$i].city
$userObj | Add-Member NoteProperty -Name "StateOrProvince" -Value $members[$i].StateOrProvince
$userObj | Add-Member NoteProperty -Name "postalcode" -Value $members[$i].postalcode
$userObj | Add-Member NoteProperty -Name "Location" -Value $members[$i].Location
$userObj | Add-Member NoteProperty -Name "Alias" -Value $members[$i].Alias
$userObj | Add-Member NoteProperty -Name "Last Name" -Value $members[$i].lastname
$userObj | Add-Member NoteProperty -Name "First Name" -Value $members[$i].Firstname
$userObj | Add-Member NoteProperty -Name "RecipientType" -Value $members[$i].RecipientType
$userObj | Add-Member NoteProperty -Name "Recipient OU" -Value $members[$i].OrganizationalUnit
$userObj | Add-Member NoteProperty -Name "Primary SMTP streetAddress" -Value $members[$i].PrimarySmtpstreetAddress
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name
$userObj | Add-Member NoteProperty -Name "Distribution Group Primary SMTP streetAddress" -Value $DG.PrimarySmtpstreetAddress
$userObj | Add-Member NoteProperty -Name "Distribution Group Managers" -Value $managers.DistributionGroupManagers
$userObj | Add-Member NoteProperty -Name "Distribution Group OU" -Value $DG.OrganizationalUnit
$userObj | Add-Member NoteProperty -Name "Distribution Group Type" -Value $DG.RecipientType
$userObj | Add-Member NoteProperty -Name "Distribution Group Recipient Type" -Value $DG.RecipientType

$output += $UserObj   

}

$output | Export-csv -Path $CSVfile -NoTypeInformation

}


;Break}

8 {

$Dgname = Read-Host "Enter the Dynamic DG name or Range (Eg. DynamicDGname , DG*,*DG)"

$AllDG = Get-DynamicDistributionGroup $Dgname -resultsize unlimited

Foreach($dg in $allDg)

{

$Members = Get-Recipient -RecipientPreviewFilter $dg.RecipientFilter -resultsize unlimited

$Total = $Members.Count

$RemoveNull = $Total-1

For($i=0;$i -le $RemoveNull;$i++)

{
$ADProps = Get-User $Members[$i].Samaccountname

$userObj = New-Object PSObject

$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $members[$i].Name
$userObj | Add-Member NoteProperty -Name "Department" -Value $members[$i].Department
$userObj | Add-Member NoteProperty -Name "Title" -Value $members[$i].Title
$userObj | Add-Member NoteProperty -Name "Phone" -Value $members[$i].Phone
$userObj | Add-Member NoteProperty -Name "Mobile" -Value $ADProps.MobilePhone
$userObj | Add-Member NoteProperty -Name "streetAddress" -Value $ADProps.streetAddress
$userObj | Add-Member NoteProperty -Name "city" -Value $members[$i].city
$userObj | Add-Member NoteProperty -Name "StateOrProvince" -Value $members[$i].StateOrProvince
$userObj | Add-Member NoteProperty -Name "postalcode" -Value $members[$i].postalcode
$userObj | Add-Member NoteProperty -Name "Location" -Value $members[$i].Location
$userObj | Add-Member NoteProperty -Name "First Name" -Value $members[$i].firstname
$userObj | Add-Member NoteProperty -Name "Last Name" -Value $members[$i].lastname
$userObj | Add-Member NoteProperty -Name "Alias" -Value $members[$i].Alias
$userObj | Add-Member NoteProperty -Name "Primary SMTP Address" -Value $members[$i].PrimarySmtpAddress
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name


Write-Output $Userobj

}

}

;Break}

Default {Write-Host "No matches found , Enter Options 1 or 2" -ForeGround "red"}

}

Open in new window

0
 

Author Comment

by:PSC
ID: 40367046
Thanks Rajitha14! That fixed the mobile phone right away. The Addresses are all showing up the same. Is there an easier way to do this?

Here is the error while running the updated script. Note that we get quite a few of these messages. I suspect one for each contact.
Cannot process argument transformation on parameter 'Identity'. Cannot convert value "" to type
"Microsoft.Exchange.Configuration.Tasks.UserIdParameter". Error: "Parameter values of type
Microsoft.Exchange.Configuration.Tasks.UserIdParameter can't be empty. Specify a value, and try again.
Parameter name: identity"
    + CategoryInfo          : InvalidData: (:) [Get-User], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-User
    + PSComputerName        : server.domain.local

Cannot process argument transformation on parameter 'Identity'. Cannot convert value "" to type
"Microsoft.Exchange.Configuration.Tasks.UserIdParameter". Error: "Parameter values of type
Microsoft.Exchange.Configuration.Tasks.UserIdParameter can't be empty. Specify a value, and try again.
Parameter name: identity"
    + CategoryInfo          : InvalidData: (:) [Get-User], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-User
    + PSComputerName        : server.domain.local

Open in new window

0
 
LVL 16

Expert Comment

by:Rajitha Chimmani
ID: 40367224
The Addresses are all showing up the same. Is there an easier way to do this? Easier way of doing what? Is there any problem with addresses now?

It appears that few of your users dont have a samaccountname and hence you are getting the warnings. Try using Distinguished name instead of samaccountname. Replace the samaccountname with distinguishedname in all places where you find the below command.

$ADProps = Get-User $Members[$i].Samaccountname

$ADProps = Get-User $Members[$i].distinguishedname
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:PSC
ID: 40368534
I made the change you suggested. The street address for the contacts are still not appearing in the exported csv. The result is below. In my last post I spoke to an "easier way" to do this. I was merely wondering if there was an easier way to obtain the end result of exporting contact information to a csv. Given that this spans across AD and Exchange I'm not sure that the script I'm using is the best tool for the job.

In a perfect word, the following fields would populate on the csv.
LastName, Firstname, email, Displayname, Department, Title, Phone, Mobile, StreetAddress, City, StateorProvince, Postalcode,recipientType,Distribution Group(s),

Sorry for the confusion.

Result:
The operation couldn't be performed because object 'domain.Local/OU/Internal/Contacts/Contact
Name' couldn't be found on 'DomainController'.
    + CategoryInfo          : NotSpecified: (:) [Get-User], ManagementObjectNotFoundException
    + FullyQualifiedErrorId : [Server=MailServer,RequestId=bf1e9b62-a127-42ce-b2dd-b538a6a25767,TimeStamp=10/8/2014 2
   :26:06 PM] B9CAEC29,Microsoft.Exchange.Management.RecipientTasks.GetUser
    + PSComputerName        : Mailserver.domain.local

Open in new window

I did confirm that the contacts DO exist in the Contacts OU in the error message above.
0
 
LVL 16

Expert Comment

by:Rajitha Chimmani
ID: 40368804
Ok. I guess the script is doing more than what you need. the lines of code that I added work only for mailboxes and the command for contacts is different. Please let me know the following details


1. Exchange version
2. Do you have any Dynamic Distribution groups?
3. The list of fields you have given. Is that the only information that you are looking for?
0
 

Author Comment

by:PSC
ID: 40368815
1. Exchange 2013
2. No
3. Yes
0
 
LVL 16

Accepted Solution

by:
Rajitha Chimmani earned 500 total points
ID: 40369414
Please try the following

$ArrayObj = @()
$AllGroups = Get-DistributionGroup -Resultsize unlimited
foreach($group in $AllGroups){
$members = Get-DistributionGroupMember $group.Name
foreach($member in $members){
if($member.recipienttype -eq "MailContact"){$ADProps = Get-Contact $member.distinguishedname}
$ADProps = Get-User $member.Distinguishedname
$userObj = New-Object PSObject

$userObj | Add-Member NoteProperty -Name "LastName" -Value $ADProps.LastName
$userObj | Add-Member NoteProperty -Name "FirstName" -Value $ADProps.FirstName
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $member.DisplayName
$userObj | Add-Member NoteProperty -Name "Department" -Value $ADProps.Department
$userObj | Add-Member NoteProperty -Name "Title" -Value $ADProps.Title
$userObj | Add-Member NoteProperty -Name "Title" -Value $ADProps.Phone
$userObj | Add-Member NoteProperty -Name "Mobile" -Value $ADProps.MobilePhone
$userObj | Add-Member NoteProperty -Name "streetAddress" -Value $ADProps.streetAddress
$userObj | Add-Member NoteProperty -Name "city" -Value $ADProps.city
$userObj | Add-Member NoteProperty -Name "StateOrProvince" -Value $ADProps.StateOrProvince
$userObj | Add-Member NoteProperty -Name "PostalCode" -Value $ADProps.PostalCode
$userObj | Add-Member NoteProperty -Name "RecipientType" -Value $member.RecipientType
$userObj | Add-Member NoteProperty -Name "DistributionGroup" -Value $Group.DisplayName
}
$ArrayObj += $UserObj
}
$ArrayObj | Export-csv Groups.csv -NoTypeInformation

Open in new window

0
 

Author Comment

by:PSC
ID: 40371411
Hi Rajitha14 - I'm away today but should be able to test tomorrow. Thank you for putting it together regardless.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question