Hi All,
I am looking for a script i can use in adaxes, that removes all delegates for an exchange O365 mailbox, and reset their MFA tokens as well. I want the script to run against the user specified in the activity scope.
I have custom scripts that work in powershell for each of these things, but i am getting tripped up when importing them into Adaxes. I will list the script i have below to do this, however it requires a login to O365 and utilizes the Exchange powershell module which confuses me. Thanks for any and all help.
# Import the Exchange Online module
Import-Module ExchangeOnlineManagement
# Connect to Exchange Online
Connect-ExchangeOnline -UserPrincipalName <AdminUPN> -ShowProgress $true
# Read users from the text file
$users = Get-Content "\\path\to\\users.txt"
foreach ($user in $users) {
# Revoke Azure MFA tokens
# $objectid = Get-AzureADUser -ObjectId $user | select objectid -ExpandProperty ObjectId
Revoke-AzureADUserAllRefreshToken -ObjectId $user
# Remove all Exchange delegates
Get-Mailbox -Identity $user | ForEach-Object {
$mailbox = $_
$delegates = Get-MailboxPermission -Identity $mailbox.Identity | Where-Object { $_.IsInherited -eq $false -and $_.User -ne "NT AUTHORITY\SELF" -and $_.AccessRights -like "*FullAccess*" }
foreach ($delegate in $delegates) {
Remove-MailboxPermission -Identity $mailbox.Identity -User $delegate.User -AccessRights FullAccess -Confirm:$false
Write-Output "Removed delegate $($delegate.User) from $($mailbox.Identity)"
}
}
}
# Disconnect from Exchange Online
Disconnect-ExchangeOnline -Confirm:$false