Q:

SharePoint Online - Remove users from the SharePoint sites, when they leave the organization (When their account becomes inactive/expired)

We use SharePoint Online in my work place and we always deal with this issue of removing users/owners manually from SharePoint sites when they leave our organization. Is there a way to automate this process of removing users from sites, when their account gets inactive/expire. 
Any suggestions are appreciated.
Thanks

A:

The fastest way would be to use PowerShell, utilizing the SharePoint Online Management shell module using code like this:
$user = "someone@yourdomain.com"
$sites = Get-SPOSite -limit all
foreach($site in $sites){
    try{
        Remove-SPOUser -Site $site.Url -LoginName $user
    } 
    catch{
        write-host $user " does not exist on "$site.Url
    }
}

Remove-SPOUser

