Is there any way to get the sync status using PowerShell Script?

Iron Contributor

Hello

 

Is there any way to get the sync status using PowerShell Script if user is doing syncing first time ?

 

Avian

13 Replies
Theres no way out of the box!

You can use the onedrivelib.dll to fetch some information via a script and it’s a bit tricky to get it to run remotely

Possible values:
Error, Shared, SharedSync, UpToDate, Syncing, ReadOnly, NotInstalled

See here:

https://blogs.msdn.microsoft.com/rodneyviana/2017/06/06/powershell-cmdlet-to-check-onedrive-for-busi...

And here:

https://www.intrust-it.com/2017/11/17/centrally-monitor-microsoft-onedrive-sync-status/

Adam

@adam deltinger I aleady saw this url and tried following script

 

Import-Module ".\OneDriveLib.dll"

Get-ODStatus -ByPath $env:OneDrive

 

Getting Syncing or OneDemandOruknown during syncing.

 

How to check in script that once status is UptoDate status, script should terminate especially when user is syncing first time and data size is large. I dont think running in infinite loop is good idea.

 

Please advise.

Avian

I think i read somewhere , this breaks if FOD is used though..

I guess writing some sort of IF statement depending on status would help!

What’s your usecase here?

@adam deltinger 

 

I created script where I am initiating ODB wizard, once user completed the wizard thne copying the contents automatically from file server to user local OneDrive cache folder. Once contents is copied, add a record with copy completion status in dashboardlog which is exist in one common repository. This script pushing thru SCCM, this will run only once. This is implemented for so many users. Now I want to track the sync status for each user. Once sync is completed then I can update in dashboardlog. I want this activity should be part of above script.

 

Let me know if you have some better idea.

 

Can you share some more information that Get-ODStatus is failed if FOD is enabled?

 

Thanks

Avian

Can’t seem to find it, so ignore that part for now :)

@adam deltinger I found it. Check this

https://github.com/rodneyviana/ODSyncService/issues/3

 

My sync is completed now it is showing status as OnDemandorUnknown instead on UptoDate. As per the above link other user is also noticed same. See the June 14th Post.

 

Avian

Have you checked ODFB usage reports?
AFAIK there are no sync status parameters in there
There are uservoice request for this simple feature to a simple solution but not evwn a We are looking into it from microsoft. It is almost like they are happy there is one or two third party vendor selling this I am sure not for a nickle.

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)

 

Hi @steveprentice,

 

Thanks for your post!... Interestingly, I spent a lot of time trying to do the same thing myself as was sure I had seen a Windows file property for this but just couldn't get it to work when I tried it. Sadly, after running your code, I got $status = "" and when I manually checked prop:303 using another util I have it didn't show any value for this either... Am wondering if maybe Microsoft recently removed/deprecated this property?

@martinzima Hey. So I've been playing with that this evening and although I still have the same properties here I've have taken a different tack, hopefully it'd help you. The below checks if something's Pinned (i.e. Always Available), and if not, sets it to be. Seems to work well for me.

 

$FILE_ATTRIBUTE_PINNED = 0x00080000
$path = "$env:OneDrive\Documents"
$folder = Get-Item $path
$attributes = $folder.Attributes
If (($attributes -band $FILE_ATTRIBUTE_PINNED) -eq 0) {
  $folder.Attributes = $folder.Attributes -bor $FILE_ATTRIBUTE_PINNED
}

 

Hi @martinzima,

 

You and @steveprentice send me down a rabithole with your conversation.
I did some digging into what you both mentioned and I figured out that the command only works when you query the folder you are currently in.
With the help of an LLM AI I created a function that reads the information from all the files in the OneDrive and outputs it back out of the function as an object.
It is still not perfect, I just noticed that the .exe files are not properly detected for whatever reason and I suspect I will encounter a few more.
If I remember I will update this site once I have completed it.

$Shell = New-Object -ComObject Shell.Application

function Get-ShellDetails {
    param (
        [string]$DirectoryPath
    )
    $ShellNamespace = $Shell.NameSpace($DirectoryPath)
    $Items = $ShellNamespace.Items()
    foreach ($Item in $Items) {
        if ($Item.IsFolder -and -not ($Item.Path -match '\.(zip|tar\.gz|7z|rar|tar|gz|bz2|xz|cab|lzma)$')) {
            Get-ShellDetails -DirectoryPath $Item.Path  # Recursive call for nested directories
        } elseif (-not ($Item.Path -match '\.(zip|tar\.gz|7z|rar|tar|gz|bz2|xz|cab|lzma)$')) {
            $ShellDetails303 = $ShellNamespace.getDetailsOf($Item, 303)
            $MergedObject = [PSCustomObject]@{
                FullName        = $Item.Path
                Attributes      = (Get-Item -Path $Item.Path).Attributes
                ShellDetails303 = $ShellDetails303
            }
            $MergedStatus.Add($MergedObject)
        }
    }