# Connect to Azure ADConnect-AzureAD# Get all guest users with an email address associated with The Brand Agency / King Street$Users=Get-AzureADUser-Filter"(UserType eq 'Guest')"-Top10000|Where-Object{($_.UserPrincipalName-like"*_thebrandagency.co#EXT#@*")-or($_.UserPrincipalName-like"*_brandagency.com.au#EXT#@*")-or($_.UserPrincipalName-like"*_thebrandagency.co.nz#EXT#@*")-or($_.UserPrincipalName-like"*_kingst.co#EXT#@*")-or($_.UserPrincipalName-like"*_brandxp.co#EXT#@*")-or($_.UserPrincipalName-like"*_queenst.co#EXT#@*")}# Display the list of users$UsersRead-Host"Press Enter to continue with the removal of the $($Users.Count) guest accounts listed above or press Ctrl + C to exit"foreach($Userin$Users){Write-Host"Removing guest account - $($User.UserPrincipalName)"Remove-AzureADUser$User}Write-Host-ForegroundColorGreen"Complete"
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.