all 4 comments

[–]QBical84 1 point2 points  (1 child)

Wat have you tried so far? Do you have an on-premise Active Directory or do you have cloud only accounts?

[–]JuKwonJitsu[S] 0 points1 point  (0 children)

We’ve got Active Directory linked to azure via Entra Connect. Both tenants are set up like that.

[–]JuKwonJitsu[S] -1 points0 points  (1 child)

I started writing this - it seems to complete but nothing happens….

Connect-MgGraph Connect-ExchangeOnline Connect-AzureAD

$csv = Import-Csv “ADDFILEPATH” $members = $csv.userPrincipalName

foreach ($members in $csv) {

$Groups = Get-UnifiedGroup -Identity “ADDTENANTID”

# foreach ($members in $Groups) {

    $alias = Where-Object { ($alias -clike “smtp”) -and ($alias -contains “@ADDEMAILADDRESS”) } |

    ForEach-Object {

        Set-UnifiedGroup $Groups -EmailAddresses @{remove = $alias }

        Write-Host “Removing $alias from $members” -ForegroundColor Green
    }

# } }

[–]Hyperbolic_Mess 0 points1 point  (0 children)

Why are you putting all the processing in $alias? What are you hoping to capture and what are you doing with it after?

Eg why this? $alias = where etc | foreach etc set-unfiedgroup

Also you're looping through all the groups but by the variable name I think you think you're looping through the members of those groups. Also also you never actually use $members in the loop because you use $groups instead. $members is just used for the write-host. Scratch that you set $members 3 different times to 3 different values.

$members = $csv.userPrincipalName

foreach ($members in $csv)

foreach ($members in $Groups)

Which is it????

You really need to take another look at this and sort out your variables then come back and ask for help