Shivani G
Shivani G

Reputation: 71

How can I check status of files/folders in OneDrive folder whether it is synced or not using c# or PowerShell?

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?

Upvotes: 1

Views: 6211

Answers (3)

Steve Prentice
Steve Prentice

Reputation: 36

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)

Upvotes: 2

An-dir
An-dir

Reputation: 465

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

Upvotes: 0

Flexan
Flexan

Reputation: 43

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...).

Upvotes: 0

Related Questions