Search code examples
c#windowspowershellonedrive

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?


Solution

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