Real "files on demand". Automatically uploading cached OneDrive user files?

Станістав Ільїн 0 Reputation points
2024-07-16T15:13:32.9266667+00:00

Hello, I recently came across a seemingly simple task, but in fact I have been unable to get OneDrive to do what I want it to do for two weeks now. I'll try to describe it briefly. The problem is that when a Windows user restarts or logs off their computer, their downloaded files in OneDrive are physically unloaded from the disk and are only available upon request.

OneDrive has a "files on demand" feature in the OneDrive settings, but it just unloads all files and only makes them available for download until the first time they are opened.

I wrote a mini-script in PS that changes the attributes of the files in the current user's OneDrive directory to archive, then the OneDrive.exe process (FileCoAuth.exe to be exact) handles the change and frees the disk of the previously opened files, they only become available over the network. This works fine in a user session, but if you associate this script with a scheduled logout or reboot task, or add it to a local LogOff policy, the script runs, the user logs out, and the documents are still physically on the disk.

I tried logging the script to track the difference in service and process execution, but nothing worked, I'm probably misunderstanding the difference between running the script in a session and in the shutdown process.

Why is it that even after I've given it a Star-sleep time of a few minutes, the download doesn't happen while file attributes have already been changed, OneDrive and even Explorer processes are running, and the internet connection is active.

If anyone has encountered something similar or knows how to solve this problem, any help and information would be greatly appreciated. Peace everyone!

Initially I edit attributes like this, I did not display the stages of process restarts and logging here.

$onedrivePath = (Get-ItemProperty -Path "HKCU:\Software\Microsoft\OneDrive\Accounts\Business1" -Name "UserFolder").UserFolder 
#$onedrivePath = $env:OneDriveCommercial  
$files = Get-ChildItem -Path $onedrivePath -Recurse  foreach ($file in $files) {             		  Write-Host $file.FullName         attrib.exe +U $file.FullName    }

UPD: I noticed two services seemingly important to this process, which when running a script in a session have a status of Started, but when executed by the scheduler on reboot or logoff they have a status of stopped. These are the services :

NgcCtnrSvc - Microsoft Passport Service Container

NgcSvc - Microsoft Passport Service.

And I can't manage their status even with local administrator privileges. But it's worth trying to run with the help of an executable file with the necessary key, I'll let you know when I get a chance to test it.

UPD: that didn't help either, I stopped the services in the user session by simulating a logout scripting situation, restarted OneDrive and it successfully uploads and downloads the files. It doesn't seem to affect the process, so far I'm out of ideas :(

OneDrive
OneDrive
A Microsoft file hosting and synchronization service.
963 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,927 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,308 questions
0 comments No comments
{count} votes