Call4Cloud | MMP-C | Autopilot | Device Preparation

Lost in Monitoring Onedrive

Patch My Pc | install & update thousands of apps

In this blog, I will explain why it’s important to monitor OneDrive and show you how to set up OneDrive monitoring on your endpoints.

When you enable KFM (OneDrive Known Folder Move) and mount some Team sites, as I showed in one of my blogs, you must ensure OneDrive is always working and your files are up-to-date.

1.PowerShell Script

Monitoring your user’s OneDrive can be a pain because there are no real event logs or register values you can monitor to ensure OneDrive is working. Luckily, you can use some OneDrive logs in the user’s local AppData folder.

the ondrive\logs\business\1 folder contains the syncdiagnostics.log

This syncdiagnostics.log will show you some important things.

  • Time stamp of the log itself
  • Syncprogressstate
  • UtcNow
the syncdiagnostic log showing the syncprogressstate: 16777216

It’s a funny thing, syncprogressstate is nowhere mentioned in Microsoft’s documentation. So getting the error codes can be a little bit hard. After some tests to break OneDrive, I noticed some things.  The syncprogressstate can be:

  • 16777216 or 0  =  “Up-to-Date”
  • 65536    = “Paused”
  • 8194 = “Not syncing”
  • 1854 = “Having syncing problems”
  • Or the value: syncprogressstate, just does not exist…

So now we have some information to begin monitoring but we still need to check some other information.

  • Is OneDrive running?
  • Is a Entra ID user logged in?
  • Compare the current time and the timestamp to see the difference.

When using Solarwinds you can create some PowerShell scripts to begin monitoring OneDrive. Of course, this is my first beta script so it’s not perfect yet. I need to test it some more… but here it is.

#Search onedrive logs in the user folders
	$folderMask = "C:\Users\*\AppData\Local\Microsoft\OneDrive\logs\Business1\*.*"
	$files = Get-ChildItem -Path $folderMask  -Filter SyncDiagnostics.log |  Where-Object { $_.LastWriteTime -gt [datetime]::Now.AddMinutes(-1440)}
	$filesfound = $files -ne $null

#search progressstate and date
$progressstate = Get-Content $files| Where-Object { $_.Contains("SyncProgressState") } 
$checkdate = Get-Content $files| Where-Object { $_.Contains("UtcNow:") }  

#Select progressstate
	$status = $progressstate | %{ -split $_ | select -index 1 }

#Check if Onedrive is active

	$ProcessActive = Get-Process OneDrive -ErrorAction SilentlyContinue
	if($processactive.count -eq 0) 
		{ 
			$checkprocess = $false
		} 
	else 
		{ 
			$checkprocess = $true
		}

#check if azuread user is logged on
	$user = Get-WMIObject -class Win32_ComputerSystem | select username
	$user.username
	$userloggedin = $user.username -match "azuread"


#####convert progressstate to name####
Function Convert-ResultCodeToName
{
	param( [Parameter(Mandatory=$true)]
	[int] $status
	)
	$Result = $status
	switch($status)
	{
		{($_ -eq 16777216) -or ($_ -eq 42) -or ($_ -eq 0)} 
		{
			$statusname = "Up-to-Date"
		}
		65536
		{
			$statusname = "Paused"
		}
		8194
		{
			$statusname = "Not syncing"
		}
		1854
		{
			$statusname = "Having syncing problems"
		}
		default 
		{
			$statusname =  "Unknown ($status)" 
		}
	}
	return $statusname
}
$Resulttext = Convert-ResultCodeToName $status

#checking if progressstate is up to date
	$state = ($progressstate -match 16777216) -or ($progressstate -match 42) -or ($progressstate -match 0) 

#comparing log file dates
	$convertdate = $checkdate | %{ -split $_ | select -index 1 }
	$convertdate = $convertdate -as [DateTime]
	$datumnow = get-date
	$TimeSpan = new-timespan -start $datumnow -end $convertdate
	$difference = $timespan.hours


#Returning solarwinds status
Try 
{
If ($userloggedin -eq  $False)
{
	write-host "No azuread user is logged on. Skipping OneDrive monitoring."
	#exit 0
}
elseif ($checkprocess -eq $false -and $userloggedin -eq $true)
{
	write-host "User logged in but Onedrive is not running!"
	#exit 1001
}
elseif ($state -eq "True" -and $difference -le 24 -and $files.count -gt 0 -and $checkprocess -match "True")
{
	write-host "Onedrive is working great! Onedrive is $resulttext and there are no syncing problems"
	#exit 0
}
else
{
	write-host "Onedrive is really really really broken! Onedrive is $resulttext | Last sync time:$difference hours ago | Beware, possible syncing problems detected"
	#exit 1001
}
}
catch
{
	Write-Warning "Value Missing"
	#exit 1001
}

2. Office Admin Center

Finally, there is a new possibility/option created by Microsoft themselves to start monitoring your OneDrive clients!

Go open config.office.com and log in with your credentials, you will notice a new tab has appeared: “Onedrive Sync”

config.office.com now has an onedrive sync option to check out the health status of the onedrive sync app

As shown above, I now have 17 devices. If you end up with zero devices, you will still need to do some manual labor before it starts working. Open the settings menu and generate a new tenant association key.

When you have copied this key, open your Intune administrative templates again and search for “Sync Admin Reports” and paste the key.

Make sure you apply this policy to all devices you want to monitor, I guess that means all of your devices…

Now let’s take a look at what the OneDrive Sync health is telling us!

the onedrive sync health overview showing the devices that run into sync errors with OneDrive. Besides the errors it also shows you the app version of OneDrive

Isn’t that beautiful? You will see all of the sync errors occurring on all of your enrolled Endpoints, even when they were last synced! I can’t be happier!

So Happy GIFs - Get the best GIF on GIPHY

A final note: Beware… it could take up to 3 days before any of your devices shows up make sure your Onedrive is up to date because you will need to use the OneDrive Sync app version 21.078

Conclusion

Implementing OneDrive is crucial to your modern workplace journey but not monitoring OneDrive will come back to bite you. Keeping your files up-to-date is just as important as keeping your Windows up-to-date. With these 2 options I showed you, you can start monitoring OneDrive on your endpoints

13 thoughts on “Lost in Monitoring Onedrive

  1. The script is great, thank you!

    One thing I noticed is that if I pause OneDrive, and then re-enable sync, the log file does not update and still shows the 65536 state.

  2. I found if I add code to delete the SyncDiagnostics.log as last step, then the code reports the correct status on next check. The log seems to only generate on some interval or when an error occurs.

    1. Hi,

      Thats indeed correct, I noticed the same thing (did not had the time to post an update bout it). the log will not update the status (after you paused onedrive) unless you kill/stop/start onedrive or indeed delete the .log file.

  3. Hi Rudy,

    thank you very much for your article. Some of our users have quite some problems with Sharepoint Sync.

    Since we do not have Solarwinds, we put everything into a Google Sheet. See the following code, maybe it helps you or somebody else.

    https://bitbucket.org/raptus-it/gsheet-http-get-data-collector/

    What i would like to know is how do you fix the issues, once you detect them with your script?

    regards

    Guy

  4. I just wanted to ask, in which scenarios does 8194 or 1854 status will come. I tried everything but this status is not showing. I wanted to test different scenarios.
    Please assist

    1. Hi,
      cf. 8194 = “Not syncing”
      8194=> when synchro has been disabled

      +1 if SyncDiagnostics.log match “SyncError”

  5. Pingback: Onedrive for Business sync error monitoring and auto remediation | Liebensraum
  6. I work in a GCC Tenant and the OneDrive sync health is not available. Reading about it, it won’t be available till June 2022. https://techcommunity.microsoft.com/t5/public-sector-blog/availability-of-the-office-cloud-policy-service-for-government/ba-p/3259201

  7. I give up. Have been trying to monitor OneDrive for our users as well. Microsoft has dozens of status codes; can’t figure out which are important and which aren’t. The config.office.com dashboard always shows green checks and no issues, but I continue to get various “errors” from the logs. Oh well, maybe some day. Would be nice if we could get notifications from the dashboard if issues.

  8. Hello there! thank you for this article and all ideas.
    Could you please share, if is published, the list of all “syncprogressstate” status?
    Thank you!

  9. Thank you for this.
    I think status code 8202 means “processing changes”

    At least that’s the code I got when my Onedrive client was showing status “processing changes”.

Leave a Reply

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

4  +  1  =  

Proudly powered by WordPress | Theme: Wanderz Blog by Crimson Themes.