Enterprise automation engineers and intranet developers building on Microsoft Graph face a critical set of API retirements across OneDrive for Business, SharePoint Online, and Office Graph Insights. As Microsoft consolidates file discovery and activity intelligence around the unified Microsoft Search API (/search/query) and Microsoft 365 Copilot Semantic Index, several long-standing v1.0 and beta endpoints are being retired:
GET /me/drive/recentandGET /drives/{id}/recent(Deprecated in favor of Microsoft Search & Activity queries)GET /me/drive/sharedWithMe(Deprecated due to cross-tenant B2B and permission enumeration changes)GET /me/insights/used,GET /me/insights/shared, andGET /me/insights/trending(Sites.Read.AllOffice Graph Insights retirement)
When these endpoints reach hard retirement, scheduled PowerShell reporting scripts, custom SharePoint Framework (SPFx) web parts, and governance bots calling them will fail with 404 Not Found or 410 Gone HTTP responses.
In this migration runbook, we provide the exact replacement architectures for each deprecated endpoint, show how to rewrite your Microsoft Graph PowerShell SDK scripts using Invoke-MgGraphRequest and /search/query, and audit your Entra ID Service Principals for legacy API dependencies.
Deprecated Microsoft Graph File & Insights Endpoints vs. Modern Replacements
| Deprecated Graph Endpoint | Legacy Use Case | Modern Replacement Endpoint | Required Permission Scope |
|---|---|---|---|
GET /me/drive/recent | List files recently opened or modified by a user | POST /v1.0/search/query (entityTypes: ["driveItem"] sorted by lastModifiedDateTime) | Files.Read.All |
GET /me/drive/sharedWithMe | List files shared with the user by internal or external collaborators | POST /v1.0/search/query with KQL filter (SharedWithUsersOWSUSER or ViewableByExternalUsers) | Files.Read.All, Sites.Read.All |
GET /users/{id}/insights/used | Audit documents recently viewed or modified by a user | Unified Audit Log (Search-UnifiedAuditLog -Operations FileAccessed,FileModified) or /search/query | AuditLogsQuery.Read.All / Files.Read.All |
GET /users/{id}/insights/shared | Audit files shared with or by a user | GET /drives/{id}/root/delta + GET /drives/{id}/items/{id}/permissions | Files.Read.All, Sites.Read.All |
Migration Pattern 1: Replace GET /me/drive/recent and /insights/used with Microsoft Search API (/v1.0/search/query)
Previously, scripts called Get-MgDriveRecent (GET /drives/{id}/recent) or Get-MgUserInsightUsed (GET /users/{id}/insights/used) to list recently modified or accessed files.
The modern replacement uses the Microsoft Search API (POST /v1.0/search/query) querying driveItem entities with Keyword Query Language (KQL) and sorting by lastModifiedDateTime:
# Connect to Microsoft Graph
Connect-MgGraph -Scopes "Files.Read.All", "Sites.Read.All" -NoWelcome
# Modern Replacement for /drive/recent & /insights/used using Microsoft Search API
$SearchPayload = @{
requests = @(
@{
entityTypes = @("driveItem")
query = @{
# KQL: Find documents modified in the last 30 days
queryString = "LastModifiedTime>=$( (Get-Date).AddDays(-30).ToString('yyyy-MM-dd') ) AND IsDocument:true"
}
from = 0
size = 25
fields = @(
"name",
"webUrl",
"lastModifiedDateTime",
"lastModifiedBy",
"size"
)
sortProperties = @(
@{
name = "lastModifiedDateTime"
isDescending = $true
}
)
}
)
} | ConvertTo-Json -Depth 6
$Response = Invoke-MgGraphRequest -Method POST -Uri "https://graph.microsoft.com/v1.0/search/query" -Body $SearchPayload
$Hits = $Response.value[0].hitsContainers[0].hits
$RecentFiles = foreach ($Hit in $Hits) {
[PSCustomObject]@{
FileName = $Hit.resource.name
LastModified = $Hit.resource.lastModifiedDateTime
ModifiedBy = $Hit.resource.lastModifiedBy.user.displayName
WebUrl = $Hit.resource.webUrl
}
}
$RecentFiles | Format-Table -AutoSize
Migration Pattern 2: Replace /drive/sharedWithMe and /insights/shared for External Sharing Audits
Many security teams previously misused /users/{id}/insights/shared or /drive/sharedWithMe to audit external file sharing across OneDrive and SharePoint Online. That approach was both incomplete (it only returned algorithmically ranked items) and is now deprecated.
To perform a complete, deterministic audit of shared files on a user's OneDrive or SharePoint site in 2026 using App-Only Certificate Authentication, query the user's OneDrive (GET /users/{id}/drive) and enumerate items via /root/delta and /permissions:
# Unattended Certificate-Based App-Only Connection (Works in Scheduled Tasks)
$TenantId = "ab85c7a1-366d-44ba-acc6-924fa0950045"
$ClientId = "c841ae33-4093-4385-8a90-6a530761f9b9"
$CertThumbprint = "BEAC429DE404B46FF030811C0C9DE00DE701C027"
Connect-MgGraph -TenantId $TenantId -ClientId $ClientId -CertificateThumbprint $CertThumbprint -NoWelcome
$TargetUserUPN = "[email protected]"
# 1. Resolve the User's OneDrive ID
$Drive = Invoke-MgGraphRequest -Method GET -Uri "https://graph.microsoft.com/v1.0/users/$TargetUserUPN/drive"
Write-Host "[+] Auditing OneDrive for $TargetUserUPN (DriveId: $($Drive.id))" -ForegroundColor Cyan
# 2. Query Drive Items via Delta API (Replaces /insights/shared)
$DeltaItems = (Invoke-MgGraphRequest -Method GET -Uri "https://graph.microsoft.com/v1.0/drives/$($Drive.id)/root/delta?`$select=id,name,webUrl,shared,file").value
# 3. Filter Only Items That Have Active Sharing Permissions
$SharedItems = $DeltaItems | Where-Object { $null -ne $_.shared }
$SharingReport = foreach ($Item in $SharedItems) {
$Perms = (Invoke-MgGraphRequest -Method GET -Uri "https://graph.microsoft.com/v1.0/drives/$($Drive.id)/items/$($Item.id)/permissions").value
foreach ($p in $Perms) {
if ($p.link -or $p.grantedToV2) {
[PSCustomObject]@{
ItemName = $Item.name
LinkScope = if ($p.link) { $p.link.scope } else { "DirectGrant" }
LinkType = if ($p.link) { $p.link.type } else { ($p.roles -join ",") }
GrantedTo = $p.grantedToV2.user.email
WebUrl = $Item.webUrl
}
}
}
}
$SharingReport | Format-Table -AutoSize
Step 3: Scan Your Local PowerShell & Automation Repository for Deprecated Cmdlets
Run the following PowerShell one-liner across your automation server or Git repositories to flag any scripts calling the retiring OneDrive or Office Graph Insights endpoints before they fail in production:
# Scan all .ps1, .js, .ts, and .cs files for deprecated Graph endpoints and SDK cmdlets
$DeprecatedPatterns = @(
"Get-MgDriveRecent",
"Get-MgDriveSharedWithMe",
"Get-MgUserInsightUsed",
"Get-MgUserInsightShared",
"Get-MgUserInsightTrending",
"/drive/recent",
"/drive/sharedWithMe",
"/insights/used",
"/insights/shared",
"/insights/trending"
)
$Regex = ($DeprecatedPatterns | ForEach-Object { [regex]::Escape($_) }) -join "|"
Get-ChildItem -Path "C:\Scripts" -Recurse -Include *.ps1,*.psm1,*.js,*.ts,*.cs |
Select-String -Pattern $Regex |
Select-Object Path, LineNumber, Line |
Format-Table -AutoSize
Key Takeaways for Microsoft 365 Developers & Admins
- Standardize on
/v1.0/search/queryfor User-Centric File Discovery: The Microsoft Search API respects SharePoint and OneDrive ACLs automatically and is the same search fabric powering Microsoft 365 Copilot. - Use
/drives/{id}/root/deltafor Security & Sharing Audits: Never rely on/insights/sharedfor compliance reporting;delta+/permissionsguarantees 100% coverage of anonymous links, organization links, and external B2B guest grants.