Checking OneDrive Synchronization Status using PnP PowerShell

Loading

OneDrive synchronization ensures that users’ files are up-to-date across devices. As an administrator, you may need to check if users’ OneDrive accounts are syncing properly. Using PnP PowerShell, you can:

Identify OneDrive sites in your organization
Check the synchronization status
Troubleshoot sync issues


Prerequisites

1️⃣ Install PnP PowerShell (if not installed)

Ensure the latest PnP PowerShell module is installed:

Install-Module -Name PnP.PowerShell -Force -AllowClobber

2️⃣ Connect to SharePoint Admin Center

To manage OneDrive sites, connect to SharePoint Online:

Connect-PnPOnline -Url "https://yourtenant-admin.sharepoint.com" -Interactive

Replace "yourtenant" with your actual SharePoint tenant name.

Use Global Administrator or SharePoint Administrator credentials.


Step 1: Get a List of OneDrive Sites

OneDrive sites follow the pattern:
https://yourtenant-my.sharepoint.com/personal/username_domain_tld

To list all OneDrive sites:

Get-PnPTenantSite | Where-Object { $_.Url -like "*-my.sharepoint.com/personal/*" } | Select-Object Url, Owner, StorageUsage, Status

Displays all OneDrive sites, their owners, storage usage, and status.


Step 2: Check OneDrive Synchronization Status

OneDrive sync status details are not directly available via PnP PowerShell. However, you can check file synchronization activity by analyzing audit logs.

Search-UnifiedAuditLog -StartDate (Get-Date).AddDays(-7) -EndDate (Get-Date) -RecordType SharePointFileOperation -Operations "FileSyncDownloadedFull" | Select-Object CreationDate, UserIds, Operation, ObjectId

Retrieves OneDrive sync events for the past 7 days.
Operation Types:

  • "FileSyncDownloadedFull" → A file was successfully synced.
  • "FileSyncDownloadedPartial" → A file was partially synced.
  • "FileSyncUpload" → A file was uploaded during sync.

Step 3: Identify Users with Sync Issues

To list users whose OneDrive sync is inactive, check the last modified files:

Get-PnPListItem -List "Documents" -PageSize 100 | Select-Object Title, FileLeafRef, Modified, Editor

If files haven’t been modified recently, sync might be inactive.

Filter Users with No Recent Sync Activity (Last 30 Days)

$thresholdDate = (Get-Date).AddDays(-30)
Get-PnPTenantSite | Where-Object { $_.Url -like "*-my.sharepoint.com/personal/*" } | ForEach-Object {
$siteUrl = $_.Url
Connect-PnPOnline -Url $siteUrl -Interactive
$lastModified = (Get-PnPListItem -List "Documents" | Sort-Object Modified -Descending | Select-Object -First 1).Modified

if ($lastModified -lt $thresholdDate) {
Write-Host "User: $($_.Owner) - OneDrive Sync may be inactive!" -ForegroundColor Red
}
}

Identifies users who haven’t synced files in the last 30 days.


Step 4: Automate OneDrive Sync Monitoring

Create a PowerShell Script (Check-OneDriveSync.ps1)

# Connect to SharePoint Admin Center
Connect-PnPOnline -Url "https://yourtenant-admin.sharepoint.com" -Interactive

# Set sync threshold (30 days)
$thresholdDate = (Get-Date).AddDays(-30)

# Get all OneDrive sites
$oneDriveSites = Get-PnPTenantSite | Where-Object { $_.Url -like "*-my.sharepoint.com/personal/*" }

foreach ($site in $oneDriveSites) {
$siteUrl = $site.Url
Connect-PnPOnline -Url $siteUrl -Interactive

# Get last modified file date
$lastModified = (Get-PnPListItem -List "Documents" | Sort-Object Modified -Descending | Select-Object -First 1).Modified

if ($lastModified -lt $thresholdDate) {
Write-Host "Sync Issue Detected: $($site.Owner) - Last Modified: $lastModified" -ForegroundColor Red
} else {
Write-Host "Sync Active: $($site.Owner) - Last Modified: $lastModified" -ForegroundColor Green
}
}

Write-Host "OneDrive Sync Check Completed!"

Automates OneDrive sync status monitoring.
Identifies users with inactive sync.


Step 5: Troubleshooting Sync Issues

1️⃣ Check OneDrive Sync Client Status

Run this command on a user’s machine:

(Get-Process "OneDrive" -ErrorAction SilentlyContinue).Responding

Returns True if the OneDrive Sync Client is running.
Returns False if OneDrive is not responding.


2️⃣ Reset OneDrive Sync Client for Users

To force OneDrive to re-sync, run:

Start-Process "C:\Program Files\Microsoft OneDrive\OneDrive.exe" /reset

Ask users to restart OneDrive manually if the issue persists.


3️⃣ Reconnect OneDrive to SharePoint

If sync issues persist, reconnect OneDrive to SharePoint:

Start-Process "odopen://sync?useremail=user@domain.com"

Replace "user@domain.com" with the actual user’s email.

Leave a Reply

Your email address will not be published. Required fields are marked *