How to Set OneDrive Files to Online-Only Using Command Line Tools
If you’re experiencing issues with a Windows PC stuck in recovery mode and need to back up your data before attempting repairs, utilizing command line tools such as Robocopy can be an efficient and effective approach. However, when dealing with OneDrive-synced files, you might want to ensure that these files are set to “Online Only” to save local storage space and avoid unnecessary backups of cloud-only files.
Understanding the OneDrive File Status
Before proceeding, it’s important to understand OneDrive’s file status indicators:
- Online-only files: These files are stored in the cloud and do not occupy local disk space. They display a cloud icon.
- Locally available files: Files that are downloaded and stored locally on your device.
- Always available files: Files set to “Always keep on this device.”
To minimize local storage use, you can convert your files to online-only status via command line or PowerShell scripting.
Steps to Move OneDrive Items to Online-Only Using PowerShell
While there isn’t a built-in command in Robocopy to directly set files to online-only, you can leverage PowerShell to modify the attributes of OneDrive files. Here’s a method you can use:
-
Open PowerShell with Administrative Privileges
-
Navigate to Your OneDrive Folder
Replace YourUserName
with your actual username:
powershell
cd "$env:USERPROFILE\OneDrive"
- Change Files to Online-Only by Invoking the
Set-FileAttributes
or Using the OneDrive Client
OneDrive provides a command-line interface to control sync status. In recent versions, Microsoft introduced the Set-Online
command:
“`powershell
Make all files in OneDrive Online-Only
Get-ChildItem -Path “$env:USERPROFILE\OneDrive” -Recurse | foreach {
# For each file, invoke the OneDrive personal or business client command
# Note: This requires the latest OneDrive version supporting the command
Invoke-Expression “$env:LOCALAPPDATA\Microsoft\OneDrive\OneDrive.exe /setonline:’$($_.FullName)'”
}
“`
Note: As of October 2023, Microsoft does not officially provide command-line parameters to individually set files to online-only via OneDrive.exe. Alternatively, you may consider:
- Manually selecting
Share this content: