Skip to content

Instantly share code, notes, and snippets.

@General-Gouda
Last active April 7, 2017 19:07
Show Gist options
  • Select an option

  • Save General-Gouda/3d61bd529ce53458f36e649af4bc763e to your computer and use it in GitHub Desktop.

Select an option

Save General-Gouda/3d61bd529ce53458f36e649af4bc763e to your computer and use it in GitHub Desktop.
ADSI to CSV
Import-Module ActiveDirectory
$MeGroups = Get-ADGroup -Filter {Mail -like "*"} -Properties Mail,Members,msExchHideFromAddressLists | Where-Object {$_.msExchHideFromAddressLists -ne $true}
Write-Host "There are" $MeGroups.Count "mail enabled groups (Security & Distribution)"
ForEach ($Group in $MeGroups) {
$GroupDN = $Group.DistinguishedName
ForEach ($Member in $Group.Members) {
$memberADInfo = Get-ADUser -Filter {DistinguishedName -like $Member} -Properties GivenName,SurName,msExchHideFromAddressLists
[PSCustomObject]@{
GroupName = $Group.Name
GroupDN = $GroupDN
MemberDisplayName = $memberADInfo.Name
MemberFirstName = $memberADInfo.GivenName
MemberLastName = $memberADInfo.SurName
MemberSamAccountName = $memberADInfo.SamAccountName
MemberDistinguishedName = $memberADInfo.DistinguishedName
MemberHiddenFromGal = if ($memberADInfo.msExchHideFromAddressLists -eq $true) {$true} else {$false}
} | Export-Csv C:\Users\richard-admin\Documents\Scripts\MailEnabled-Users.csv -NoTypeInformation -Append -NoTypeInformation -Append
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment