Hi ,
I’ve got a script that is removing the users from the distributions groups and 99% this is working like it should.
However when the user is member of one of the below DistributionGroupsLists
*All-engineering
*All-engineering-Vn
*all_engineering_test
the script is not able to remove the user from any of these lists and throws an error that multiple entries where found for *all-engineering and stops completely.
what needs to be modified in the below mentioned code to solve this error?
Import-Module $((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\") -Filter CreateExoPSSession.ps1 -Recurse ).FullName | Select-Object -Last 1) Connect-EXOPSSession -UserprincipalName $admin $users = import-csv C:\Users\Public\Documents\CSV\toRemove.csv #active users foreach($user in $users){ write-log -message "Find distributiongroups for user: $($user.email)" -Level Info -Path $logpath $email = $user.email $mailbox = Get-Mailbox -Identity $email $DN=$mailbox.DistinguishedName $Filter = "Members -like ""$DN""" $DistributionGroupsList = Get-DistributionGroup -ResultSize Unlimited -Filter $Filter Write-host `n Write-host "Listing all Distribution Groups:" Write-host `n $distlist = $DistributionGroupsList | ft $DistributionGroupsList | ft ForEach ($item in $DistributionGroupsList) { Remove-DistributionGroupMember -Identity $item.DisplayName –Member $email -Confirm:$false } Write-host `n Write-host "Successfully removed" write-log -message "distributiongroups succesfully removed for user: $($user.email)" -Level Info -Path $logpath } write-log -message "Removing assigned phonenumber in Teams please wait...." -Level Info -Path $logpath write-host -ForegroundColor Cyan "Removing assigned phonenumber in Teams please wait...." . C:\Users\Public\Documents\PowerShellScripts\RemovePhoneNrTeams.ps1
thanks for your suggestions
Paul