Last active
April 7, 2017 19:07
-
-
Save General-Gouda/3d61bd529ce53458f36e649af4bc763e to your computer and use it in GitHub Desktop.
ADSI to CSV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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