The Brand Agency Remove old guest accounts from Azure AD related to The Brand Agency, allowing the ability to share content again.

Created by Josh Heglund
# Connect to Azure AD

# Get all guest users with an email address associated with The Brand Agency / King Street
$Users = Get-AzureADUser -Filter "(UserType eq 'Guest')" -Top 10000 | Where-Object { 
    ($_.UserPrincipalName -like "**") -or 
    ($_.UserPrincipalName -like "**") -or
    ($_.UserPrincipalName -like "**") -or
    ($_.UserPrincipalName -like "**") -or
    ($_.UserPrincipalName -like "**") -or
    ($_.UserPrincipalName -like "**")

# Display the list of users

Read-Host "Press Enter to continue with the removal of the $($Users.Count) guest accounts listed above or press Ctrl + C to exit"

foreach ($User in $Users) {
    Write-Host "Removing guest account - $($User.UserPrincipalName)"
    Remove-AzureADUser $User

Write-Host -ForegroundColor Green "Complete"

Comments (0)


You can clone a snippet to your computer for local editing. Learn more.