Oamk users have been migrated to the University of Oulu’s M365 tenant on May 20, 2024. For some of them, the User Principal Name (UPN) has also changed, but everyone still receives emails with the same email addresses as before. In order for your users to successfully re-share rights to documents to Oamk users and add Oamk users back to those Teams groups where they have previously been as guest members, the administrator of the M365 environment must clean up the old oamk.fi and students.oamk.fi guest accounts from Azure.
it can be done like this (two options)
1. option: delete individual users
- 1st phase, delete user (Tenant Administrator)
How to create or delete users in Microsoft Entra ID – Microsoft Entra | Microsoft Learn - 2nd phase, permanently delete user (Tenant Administrator)
Restore or permanently remove recently deleted user – Microsoft Entra | Microsoft Learn - 3rd phase, invite user again to the Teams (User; team owner)
Add guests to a team in Microsoft Teams – Microsoft Support
2. option: use a script to delete all old account from Oamk’s retired tenant
(NB: The code was updated on May 28, so that it will not remove new guest users added on May 20th or later):
# Connect-MgGraph api with write privileges
Connect-MgGraph -Scopes "User.ReadWrite.All"
# Search all users with userprincipalname containing "_oamk" or "_students.oamk" and "EXT"
$OamkUsers = Get-MgUser -all -filter "userType eq 'Guest'" | Where-Object {$_.userprincipalname -like "*_oamk.fi*EXT*" -or $_.userprincipalname -like "*_students.oamk.fi*EXT*"}
Write-Host "Total usercount:" $OamkUsers.count
$date = Get-Date -Year 2024 -Month 5 -Day 20 -Hour 23 -Minute 59
# Loop through userlist and delete
foreach ($user in $OamkUsers) {
#$user.UserPrincipalName
$created = (get-mguser -UserId $user.Id -Property displayname, id, mail, userprincipalname, CreatedDateTime).CreatedDateTime
if($created -lt $date)
{
Write-Host "Deleting user $($user.userPrincipalName)"
Remove-MgUser -UserId $user.Id
}
}
You could also use the $_.userprincipalname
for a certain username.
The script above does not remove users from the Entra recycle bin, from which the M365 tenant administrator should remove them separately. See: remove the recently deleted user permanently, as adviced on Microsoft Entra instructions. (This can be done by the M365 tenant administration only.)
Once the removal is done, only then should the team owner re-add the guest users to their team: it is safest to use the UPN format of the username, which is the format the user uses to log into the M365 service. Please see Add guests to a team in Microsoft Teams – Microsoft Support
Sometimes, after cleaning up, the end user still has difficulties inviting Oamk users as guest users, likely due to the Teams software cache. In these situations, an invitation sent by the inviter’s M365 administrator from the Entra ID portal works more reliably.