[PowerShell]Get all distribution list and members from AD with PowerShell

The following script will create a csv file for every distribution list with the members listed:

$allDL=get-adgroup -filter 'GroupCategory -eq "Distribution"' | sort name|select SamAccountName

foreach($dl in $allDL){

$filename=($dl.SamAccountName).ToString()
Get-ADGroupMember -identity $dl.SamAccountName|select-object name,SamAccountName,distinguishedName,objectClass|Export-Csv -Path $filename".csv" -NoTypeInformation

}

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.