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.
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."
}
}