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.



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){
        Remove-SPOUser -Site $site.Url -LoginName $user
        write-host $user " does not exist on "$site.Url


  • Thanks so much for your response. A quick question - If i provide URL of a site collection as site Url, will this code remove user from the just the root site or all the sub-sites of that site collection?
    – AXA240778
    Feb 14 '17 at 1:30
  • It completely removes them from the site collection Feb 14 '17 at 1:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.