Question : Powershell script to check each Security group which are not mail enabled and remove an contacts from those groups.

Hi,

Powershell script to check each Security group which are not mail enabled and remove an contacts from those groups.

The query has to be specific to securit groups and Non mail enabled only.
if mail enabled do nothing.

Log the changes into a csv.

Regards
sharath

Answer : Powershell script to check each Security group which are not mail enabled and remove an contacts from those groups.


The command you have there is safe, just looks, no changes.

If it finds the right group and you want to test again we can add -WhatIf onto the end of Remove-QADGroupMember (as below) as another safety-net.

Chris
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
# 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"
Random Solutions  
 
programming4us programming4us