Lost in monitoring Onedrive

Last Updated on April 21, 2022 by rudyooms

In this blog, I will be showing you why it’s very important to monitor OneDrive and how you could set up Onedrive Monitoring on your endpoints.

When you enabled KFM and mounted some Team sites as I showed in one of my blogs, you have to make sure OneDrive is always working and your files are up-to-date.

I will show you the 2 options you have to start monitoring OneDrive on your endpoints

  1. PowerShell Script
  2. OneDrive admin center

1.PowerShell Script

Monitoring your user’s OneDrive can be a true pain because there are no event logs or register values you can monitor to make sure OneDrive is working. Luckily there is some kind of log file in the user’s local AppData folder.

This syncdiagnostic.log will show you some important things.

  • Time stamp of the log itself
  • Syncprogressstate
  • UtcNow

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 an azuread\ user logged in?
  • Compare current time and the Timestamp to get 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”

As shown above, I now have 17 devices. If you end up with zero devices, you will still need to do some manual labour 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!

Isn’t that beautiful? You are going to see all of the sync errors that are occurring on all of your enrolled Endpoints even when it was 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

12 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 *

  +  44  =  48