Hi @Marija Zorić ,
It is recommended that you use PowerShell to export the user information list to a CSV file so that you can see all users.
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Parameters
$SiteURL="https://tenant.sharepoint.com/sites/sitename"
$CSVPath = "C:\Temp\UserInfo.csv"
#Get Credentials to connect
$Cred= Get-Credential
Try {
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Get the User Information List
$List=$Ctx.Web.SiteUserInfoList
$FieldColl = $List.Fields
$Ctx.Load($List)
$Ctx.Load($FieldColl)
$Ctx.ExecuteQuery()
#Get All Items from User Information List
$ListItems = $List.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())
$Ctx.Load($ListItems)
$Ctx.ExecuteQuery()
#Array to Hold Result - PSObjects
$ListItemCollection = @()
#Fetch each list item value to export to excel
ForEach($Item in $ListItems)
{
$ExportItem = New-Object PSObject
ForEach($Field in $FieldColl)
{
$ExportItem | Add-Member -MemberType NoteProperty -name $Field.InternalName -value $Item[$Field.InternalName]
}
#Add the object with property to an Array
$ListItemCollection += $ExportItem
}
#Export data to CSV File
$ListItemCollection | Export-Csv -Path $CSVPath -NoTypeInformation -Force
Write-host "User Information List has been Exported to CSV!'" -f Green
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
Then use PowerShell remove the user you want to remove.
#Import SharePoint Online module
Import-Module Microsoft.Online.SharePoint.Powershell -DisableNameChecking
Function Delete-SPOUser()
{
param
(
[Parameter(Mandatory=$true)] [string] $AdminCenterURL,
[Parameter(Mandatory=$true)] [string] $SiteURL,
[Parameter(Mandatory=$true)] [string] $UserID
)
Try {
#Get Credentials to connect
$Cred = Get-Credential
#Connect to SharePoint Online
Connect-SPOService -Url $AdminCenterURL -Credential $Cred
#Remove user from user information list
Remove-SPOUser -Site $SiteURL -LoginName $UserID
Write-host -f Green "Removed the User '$UserID' from $SiteURL"
}
Catch {
write-host -f Red "Error Deleting Orphan Users!" $_.Exception.Message
}
}
#Set Variables
$AdminCenterURL="https://tenant-admin.sharepoint.com/"
$SiteURL="https://tenant.sharepoint.com/"
$UserID="username.com#EXT#@crescent.onmicrosoft.com"
#Call the function to delete the user from user information list
Delete-SPOUser -AdminCenterURL $AdminCenterURL -SiteURL $SiteURL -UserID $UserID
For more information, please refer to:
Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.
Hope this helps.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.