0

In SharePoint Online I notice deleting users from Office 365 does not delete them from groups in SharePoint Online https://support.microsoft.com/en-gb/help/3026385/how-to-remove-users-from-sharepoint-online You have to delete them from every site collection from the hidden UserInfo List. This is loads of admin when you have thousand of users and hundreds of site collection – Microsoft should delete them here as well? Has anybody a full-proof script/tool that does this deletion fron UserInfo for accounts with no Office 365 account?

  • What happends when you remove the users that has maybe left the company and used to worked on certain documents and listitems? I think you should keep them for the sake of having a record of who did what. – Christoffer Feb 20 '18 at 13:04
  • If the user is removed from UserInfo the properties on the docuements they uploaded such as "modified by" remain in place but the user is removed from all permission groups in the site collection – Steve Feb 21 '18 at 12:02
0

You can use PowerShell script to check if the users are in Azure AD and remove the Orphaned users from site collection:

  1. Checking the user in Azure AD

    function Checkorphaneduser(){
    Param( [Parameter(Mandatory=$true)] [string]$AzureUser )
    $ADUser=Get-Msoluser -UserPrincipalName $AzureUser -Erroraction SilentlyContinue
    if ($ADUser -ne $null)
         {
           return $true
         }
         Else
         {
         return $false 
         }
    }
    
  2. Get Orphaned Users from Site Collection

    $Users = Get-SpoUser "$Sitename"         
    $OrphanedUsers = @()
    foreach($User in $Users)
    {
        #Exclude Built-in User Accounts , Security Groups 
        if(($User.DisplayName.ToLower() -ne "nt authority\authenticated users") -and
          ($User.LoginName.ToLower() -ne "sharepoint\system") -and
          ($User.LoginName.ToLower() -ne "App@Sharepoint") -and
          ($User.LoginName.ToLower() -notlike "ylo001\_spocrwl*") -and
          ($user.IsGroup -eq $false ) #-and
           )
        {
          $AccName = $User.LoginName    #UserName
            if ( ( Checkorphaneduser $AccName) -eq $false )
            {
                Write-Host "$($User.LoginName) from $($Sitename) doesn't Exists in Azure AD!"
    
                  $strOut += $User.LoginName+"`r`n"
                   $strOut|Out-File $Output                   
                  $OrphanedUsers+=$User.LoginName
            }
            }
        }
    
  3. Remove Orphaned Users from Site Collection

     if($OrphanedUsers.Count -eq 0)
    {
     Write-host "There is no Orphaned user in $($Sitename)"
    }
    Else
    {
      $Remove=Read-Host "Do You want remove Orphaned Users Yes:No :"
      If($Remove.ToUpper() -eq "YES")
      {
    
           foreach($OrpUser in $OrphanedUsers)
           {
            Remove-SPOUser -Site $Sitename -LoginName $OrpUser
           Write-host "Removed the Orphaned user $($OrpUser) from $($Sitename) "
           }
       }
      Else{
      }
     }
      Get-pssession |Remove-PSSession
    

More detailed script check the blog: How to find and delete Orphaned Users from SharePoint Online

  • Thanks for that, it appears you need global admin rights to run it so its not something I can pass to the service desk to run, they will have to manually do the deletion from the GUI in the user leaver process. – Steve Feb 21 '18 at 12:24
  • MS say: 1 Delete the user from Office 365 Admin Center 2 Delete user from each site collection 3 Using the Remove-SPOUSER MS decision to split this into two steps, are related with the consequence of removing users from the User Information List, removing the user will remove any lookup to that user, for example : If a user is the last modified person of a document, name will still show after you remove user, but if click on the link it will no longer work You can use the Get-SPOSite, to get a list of all site collections, and then use this list to run against the Remove-SPOUSER. – Steve Mar 20 '18 at 15:38

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.