# Get the groups
Get-QADGroup -SearchRoot "OU=groups,DC=domain,DC=com" -SizeLimit 0 `
-LdapFilter "(!(legacyExchangeDN=*))" | ForEach-Object {
$Group = $_
# Get the contacts from the group
Get-QADGroupMember $Group.DN -Type Contact | ForEach-Object {
# Log file output
$_ | Select-Object @{n='GroupName';e={ $Group.Name }},
Name, DN
# Remove the member from the group
Remove-QADGroupMember $Group.DN -Member $_.DN -WhatIf
}
# Write the log file
} | Export-Csv "LogFile.csv"
|