SharePoint & OneDrive - Access Issues on Reactivated Accounts

Bulk-fixing SharePoint/OneDrive access errors caused by stale user identity (SID) caching on Microsoft 365 accounts that were disabled and then reactivated.

Problem

When a user account in Microsoft 365 was first disabled and later reactivated, "Access Denied"-style errors started appearing when accessing previously shared files/folders on SharePoint and OneDrive. The problem persisted even though the user's Azure AD account and group memberships looked correct.

Cause

SharePoint/OneDrive caches each user in a site collection's own "User Information List" (People.aspx) using the old SID/identity. Even though the identity is refreshed on the Azure AD side once the account is reactivated, this per-site-collection cache keeps matching the stale identity, causing access to be denied (a user profile mismatch).

Solution

All site collections were scanned via SharePoint Online Management Shell, and the affected user's stale profile record was removed from each one with Remove-SPOUser; on their next access, SharePoint automatically re-added the user with the current identity, resolving the access issue. Instead of doing this manually across hundreds of sites, a PowerShell script (Fix-OneDriveAccess.ps1) was written to automate it: it connects with SharePoint Admin rights, lists every site with Get-SPOSite -Limit All, and runs Remove-SPOUser against each one.<br><br>Script and full source: <a href="https://github.com/seyfullahbilgic/sharepoint-onedrive-access-fixer" target="_blank" rel="noopener">GitHub - sharepoint-onedrive-access-fixer</a>

<#
.SYNOPSIS
    Yeniden aktif edilen hesaplarda oluşan SharePoint ve OneDrive erişim sorunlarını toplu olarak çözer.

.DESCRIPTION
    Pasif edilip tekrar aktif edilen kullanıcıların SharePoint/OneDrive üzerindeki eski SID/Identity
    önbelleğini (People.aspx / User Information List) tüm site koleksiyonlarından topluca temizler.

.PARAMETER AdminUrl
    SharePoint Admin Center URL adresi (Örn: https://contoso-admin.sharepoint.com)

.PARAMETER TargetUserUPN
    Erişim sorunu yaşayan kullanıcının UPN / E-posta adresi

.EXAMPLE
    .\Fix-OneDriveAccess.ps1 -AdminUrl "https://contoso-admin.sharepoint.com" -TargetUserUPN "user@contoso.com"
#>

[CmdletBinding()]
param (
    [Parameter(Mandatory = $true, HelpMessage = "SharePoint Admin Center URL'sini girin.")]
    [string]$AdminUrl,

    [Parameter(Mandatory = $true, HelpMessage = "Sorunlu kullanıcının UPN adresini girin.")]
    [string]$TargetUserUPN
)

begin {
    Write-Host "SharePoint Online Yönetim Modülüne bağlanılıyor..." -ForegroundColor Cyan
    try {
        Connect-SPOService -Url $AdminUrl
        Write-Host "Bağlantı başarılı!" -ForegroundColor Green
    }
    catch {
        Write-Error "SharePoint Admin Merkezine bağlanılamadı: $_"
        return
    }
}

process {
    Write-Host "`nTüm Site Koleksiyonları taranıyor..." -ForegroundColor Cyan
    $allSites = Get-SPOSite -Limit All

    Write-Host "Toplam $($allSites.Count) site bulundu. '$TargetUserUPN' kullanıcısı temizleniyor...`n" -ForegroundColor Yellow

    foreach ($site in $allSites) {
        try {
            # Kullanıcıyı site koleksiyonundan siler (People.aspx'teki işlemi otomatize eder)
            Remove-SPOUser -Site $site.Url -LoginName $TargetUserUPN -ErrorAction Stop
            Write-Host "[BAŞARILI] $TargetUserUPN -> $($site.Url)" -ForegroundColor Green
        }
        catch {
            # Kullanıcı sitede zaten yoksa veya erişim kısıtlıysa hata bastırılır
            Write-Host "[ATLANDI] $($site.Url)" -ForegroundColor Gray
        }
    }
}

end {
    Write-Host "`nİşlem tamamlandı! Kullanıcının paylaşılan bağlantılara tekrar erişmeyi denemesini sağlayın." -ForegroundColor Green
}

View solution source on GitHub