1

I want to check the status (Available when online/ Available on this device) of files residing in OneDrive folder either using C# or PowerShell. I want to check whether file is available on disk, basically check the sync status of files or folder.

enter image description here

Is there any possible way to get this status?

Shivani G
  • 71
  • 2
  • 13
  • Was not able to validate as i am not at my desk, but there seems to be a solution at Microsoft: https://learn.microsoft.com/en-us/archive/blogs/rodneyviana/powershell-cmdlet-to-check-onedrive-for-business-or-onedrive-personal-status – An-dir Apr 11 '22 at 10:22
  • @An-dir, Thanks for replying. This article is providing information about complete Onedrive folder.I want to check the status of individual folder/files in side this OneDrive folder. – Shivani G Apr 11 '22 at 10:30
  • You should read again. It has a parameter called "bypath" that might do what you expect. it is documented right there: https://github.com/rodneyviana/ODSyncService/tree/master/Binaries/PowerShell – An-dir Apr 11 '22 at 17:18

3 Answers3

2

The dll mentioned in this thread is good, but I don't want to have to distribute that to everyone's machines, so I came up with an alternative. The script that follows would check OneDrive for a folder called Documents and returns its status.

# ID 303 = "Availability status" | The status is generally one of the following...
# "Always available on this device", "Available on this device", "Available when online"
$OneDriveDocs = "$env:OneDrive\Documents"
$Shell = (New-Object -ComObject Shell.Application).NameSpace((Split-Path $OneDriveDocs))
$Status = $Shell.getDetailsOf($Shell.ParseName((Split-Path $OneDriveDocs -Leaf)),303)
0

This answer or other answers may be able to help achieve your goal (Sorry if this isn't a real answer, I am unable to comment on posts yet...).

Flexan
  • 33
  • 5
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 11 '22 at 09:56
  • @Flexan I tried this method and I'm getting below exception. System.ArgumentException: 'Value does not fall within the expected range. (Parameter 'handle')' – Shivani G Apr 11 '22 at 11:54
0

Some installations have problems when trying to use the byPath parameter.

You may test if your installations are affected and if the beta is a workaround for you.

Current Version: https://github.com/rodneyviana/ODSyncService/tree/master/Binaries/PowerShell

Beta Version: https://github.com/rodneyviana/ODSyncService/blob/master/Binaries/Beta/OneDriveLib_OnDemand.zip

Unblock-File -Path "C:\ODTool\OneDriveLib.dll" # change path if necessary
Import-Module "C:\ODTool\OneDriveLib.dll"

Get-ChildItem $env:OneDrive | foreach {
$_ | select *,@{Name="ODStatus";Expression={Get-ODStatus -ByPath $_}}
} | Format-Table ODStatus,FullName 

You may format your output using the "Format-Table"

If you have "OnDemandOrUnknown" often/always then add information to this: https://github.com/rodneyviana/ODSyncService/issues/36

An-dir
  • 465
  • 2
  • 13