Running out of disk space on Windows? OneDrive sync acting up? These are the exact PowerShell commands our IT team uses every day to diagnose and fix storage issues for businesses across Rhode Island and beyond.
Bookmark this page. You'll need it.
Check Disk Space
Before fixing anything, know where you stand. These commands give you the full picture in seconds.
Quick Space Check (in GB)
Get-PSDrive C | Select-Object @{N='UsedGB';E={[math]::Round($_.Used/1GB,2)}}, @{N='FreeGB';E={[math]::Round($_.Free/1GB,2)}}
What's Eating Space? (Top Folders)
Get-ChildItem "C:\Users\USERNAME" -Directory -Force | ForEach-Object {
$size = (Get-ChildItem $_.FullName -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum
[PSCustomObject]@{Folder=$_.Name; GB=[math]::Round($size/1GB,2)}
} | Sort-Object GB -Descending | Select-Object -First 10
OneDrive Folder Breakdown
Get-ChildItem "$env:USERPROFILE\OneDrive" -Directory | ForEach-Object {
$size = (Get-ChildItem $_.FullName -Recurse -File -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum
[PSCustomObject]@{Folder=$_.Name; SizeGB=[math]::Round($size/1GB,2)}
} | Sort-Object SizeGB -Descending | Format-Table -AutoSize
Pro Tip: Replace USERNAME with your actual Windows username, or use $env:USERNAME to auto-detect it.
Move Files to OneDrive (Cloud-Only)
This is the big one. Moving files to OneDrive's cloud-only mode frees up local disk space while keeping everything accessible. Here's the safe, step-by-step process.
Step 1: Create Destination Folder
New-Item -Path "C:\Users\USERNAME\OneDrive\Downloads-Archive" -ItemType Directory -Force
Step 2: Preview What Will Move (Dry Run)
robocopy "C:\Users\USERNAME\Downloads" "C:\Users\USERNAME\OneDrive\Downloads-Archive" /E /MOV /L
Step 3: Actually Move the Files
robocopy "C:\Users\USERNAME\Downloads" "C:\Users\USERNAME\OneDrive\Downloads-Archive" /E /MOV
Step 4: Set Folder to Cloud-Only (Free Local Space)
attrib +U -P "C:\Users\USERNAME\OneDrive\Downloads-Archive" /S /D
Important: OneDrive must finish syncing to cloud BEFORE local space is freed. Check the OneDrive tray icon for sync progress. This can take hours for large folders.
Fix Path Too Long Issues
Windows has a 260-character path limit that causes sync failures and "file not found" errors. Here's how to find and fix them.
Find Paths Exceeding 260 Characters
Get-ChildItem "C:\Users" -Recurse -ErrorAction SilentlyContinue |
Where-Object { $_.FullName.Length -gt 260 } |
Select-Object FullName, @{N='Length';E={$_.FullName.Length}} |
Sort-Object Length -Descending
Fix: Map a Drive Letter to Shorten Path
# Map Z: to the deep folder
subst Z: "C:\Users\Username\OneDrive\Really\Deep\Folder\Structure"
# Work from Z:\ instead
# Remove when done:
subst Z: /D
Fix: Use Robocopy with Long Path Support
robocopy "\\?\C:\VeryLongPath\Folder" "C:\Shorter\Path" /E /COPYALL /R:0
Fix: Delete Stubborn Long Path Folders
# Create empty folder, mirror it (deletes everything)
mkdir C:\empty
robocopy C:\empty "\\?\C:\Path\To\Problem\Folder" /MIR
rmdir C:\empty
Fix: Enable Long Paths System-Wide (Requires Admin + Reboot)
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1
Fix Invalid Characters
OneDrive won't sync files with certain characters. Find them before they cause problems.
Find Files with Problematic Characters
Get-ChildItem "C:\Users" -Recurse -ErrorAction SilentlyContinue |
Where-Object { $_.Name -match '[#%&{}\\<>*?/$!''":@+`|=]' } |
Select-Object FullName, Name
Invalid Characters for Windows/OneDrive: \ / : * ? " < > |
Problematic for OneDrive: # % & { }
Free Up Space Fast
Empty Recycle Bin
Clear-RecycleBin -Force
Restart OneDrive (Force Sync/Release)
Stop-Process -Name "OneDrive" -Force
Start-Process "$env:LOCALAPPDATA\Microsoft\OneDrive\OneDrive.exe"
Find OneDrive Conflict Files
Get-ChildItem "$env:USERPROFILE\OneDrive" -Recurse -File -ErrorAction SilentlyContinue |
Where-Object { $_.Name -match '\(1\)|\-conflict\-|\.conflicted' } |
Select-Object FullName
OneDrive Settings to Check
- Files On-Demand: Settings → Sync and backup → Advanced settings → Files On-Demand
- PC Folder Backup: Settings → Sync and backup → Manage backup (can auto-redirect Downloads)
- Free up space: Right-click any OneDrive folder → "Free up space"
Key Insight: If you move files to OneDrive but space doesn't free up, OneDrive is keeping local copies. Use "Free up space" or the attrib +U -P command to make them cloud-only.
Still Struggling with Storage Issues?
These commands work great for one-off fixes. But if your business is constantly battling disk space, sync failures, or OneDrive headaches—it's time for proactive IT management.
AIBridges provides managed IT services for businesses in Rhode Island and Massachusetts. We monitor storage, automate cleanups, and prevent these issues before they slow you down.
Get a Free IT Assessment