Skip to content

Instantly share code, notes, and snippets.

@movalex
Last active August 29, 2023 10:00
Show Gist options
  • Save movalex/ffde51ed67e1d4ac6909a64e8e22a54f to your computer and use it in GitHub Desktop.
Save movalex/ffde51ed67e1d4ac6909a64e8e22a54f to your computer and use it in GitHub Desktop.
Remove unsynced OneDrive files with Zero Disk Size
$files = Get-ChildItem -Recurse "*.*"
foreach ($f in $files) {
If ($f.attributes -eq 4199968) {
$outfile = $f.FullName
$attrs = $f.attributes
Write-Output "file: $outFile`nlen: $((Get-Item $f).length)`nattrs: $attrs"
Remove-Item $f
echo $outfile >> files.txt
}
}

WARNING

files will be removed!


If you dont have access to your OneDrive anymore, and some of the files on your drive weren't synced fully, you would probably want to restore those files from backup. However one won't be able to copy those files from the backup, because despite they are empty, they look as if they are normal files already existing locally. Typically if you try to copy those files, you get an error Error 0x8007016A: The cloud file provider is not running.

Hence the purpose of the script. It will list all the files in the current directory recursively and find those with the attributes equal to 4199968. Those are the empty files that was not synced from OneDrive.

Then the script removes those files, so you could merge them back again from the backup drive. The list of the removed files will be saved to the files.txt file.

Use this script on your own risk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment