-1

Image of CSV

I have the following csv file ( lets name it del.csv )

I would like exchange to read all "Distribution Lists" on all rows under "column A" And remove ALL members from them.

Please advise this, Thanks.

1 Answer 1

0

Getting the data of CSV file via PowerShell:

get specific cell value in csv file using powershell

And you could try this "Remove-DistributionGroupMember -Identity "Technical Support" -Member "Jan Dryml" " please see the link :Removing all Members in a Distribution Group

Updated: Remove group directly.

$DGs=Import-Csv C:\Users\<UserName>\Desktop\DGS.csv    
$DGs | foreach {
$Group= $_.Group
IF ($Group) { 
Write-Output $Group
Remove-DistributionGroupMember -Identity $Group
Write-Output "Remove Success."
}

}

Or

$DGs=Import-Csv C:\Users\<UserName>\Desktop\DGS.csv 
$DGs | foreach {
$Group= $_.Group
IF ($Group) { 
Write-Output $Group
$list = Get-DistributionGroupMember -Identity $Group
$list | % {
   Remove-DistributionGroupMember -Identity $Group -Member $_.Name -Confirm:$false
   Write-Output "Remove Success."
   }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you fro your reply, I have been using this : link To add users using the same file. i want to have something similar, to remove all users maybe you have an idea of a script in mind ? Thanks.
Thank you My friend, you saved my a** :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.