Azure Active Directory \ Remove User

This is a way to remove (NOT Disable) user accounts in batches. 

Please use this carefully, I am not responsible for use or results of this script

# I will follow my actual protocols for removal of accounts since I always want to show best practices. 

#1 I get my data from HR or some other process to alert me some users need to be decommissioned , fired, quit, contract up etc...  
$UserAccountsfromHR = Get-Content "C:\Users\scott\Documents\WindowsPowershell\AzureAD\HR-Remove-Accounts.txt"
$UserAccountsfromHR

#1.5 !!!! Run the snippet in #1 ONLY and review the output on the screen to make sure you are importing the correct data from source !!!!


#2 Run this command to verify I have correct infromation on these accounts and they are found in AAD 
#Decalre Array


$MyUserArray = @()

Foreach ($userUPN in $UserAccountsfromHR){

    $MyUserArray += Get-AzureADUser | Where{$_.UserPrincipalName -eq $userUPN} | Select DisplayName, ObjectID, UserPrincipalName, AccountEnabled

}

$MyUserArray | Tee-Object C:\Temp\MyUserArrayLog.txt -Append

#2.5 Run the Snippet in #2 next to review the output to the screen and make sure these are the accounts you want to remove. 


#3 Make sure all results are correct in prior steps, if anything looks out of the norm, STOP and ask someone about it 
# I use the ObjectID due to the fact these are unique in the AAD

Foreach($ObjectID in $MyUserArray){

    $ObjectID | Tee-Object C:\Temp\UsersRemovedLog.txt -Append


    Remove-AzureADUser -ObjectId $ObjectID.ObjectID 

}