Free up computer space by forcing OneDrive Storage Sense to your users.

OneDrive Space Management
In today's digital workspace, managing storage effectively is crucial for maintaining employee productivity and ensuring seamless operations within an organization. The OneDrive space management solution addresses a common problem faced by many companies: the constraints of local disk space on devices. With increasing amounts of data and files, employees often find themselves struggling with limited storage capabilities. We explore how OneDrive's space management can resolve these challenges.
How the OneDrive Solution Works
The OneDrive space management solution automatically converts already-synced files on company devices to online-only status, denoted by cloud icons. This means that while the files remain accessible and visible to users, they are no longer taking up valuable local storage space. When a user clicks on these files, they download automatically from the Microsoft cloud storage, allowing easy access without compromising employee productivity.
This process is seamless, ensuring all data remains safe and secure within the Microsoft ecosystem. As a result, employees can continue to work with important files without needing to constantly manage local storage on their devices.
Key Benefits of OneDrive Space Management
The benefits of adopting a OneDrive space management solution are manifold. Firstly, it significantly reclaims local storage without the need for new hardware purchases. Organizations can optimize existing resources efficiently, avoiding unnecessary expenditures.
Secondly, there is zero data loss risk involved in this process. The files are neither deleted nor misplaced—only stored more efficiently in the cloud. This ensures that every piece of important data remains intact for future use.
Finally, the minimal user impact is a key advantage. Since files are still accessible with just a click, employees do not experience major disruptions in their workflow. With OneDrive's intelligent management, companies can maintain productivity while addressing storage constraints.
In conclusion, the OneDrive space management solution streamlines storage management, effectively resolving issues associated with local disk space without compromising the user's ability to access necessary files. This innovative approach enables organizations to remain agile in a rapidly changing digital landscape, ensuring that productivity and efficiency are sustained.

How to Deploy the script?
Here's the script. it runs in the context of the user.
Note this was designed for OneDrive for Business, not personal. This is meant to be ran using a deployment tool or it even may work in a login script.
<#
.SYNOPSIS
Automates OneDrive "Free up space" by converting files to online-only
.DESCRIPTION
This script finds OneDrive files and converts them to online-only status,
freeing up local disk space while preserving all files in the cloud.
.PARAMETER ExcludeFolders
Comma-separated list of folder names to exclude from conversion
.PARAMETER MinimumAge
Only convert files that are older than this many days
.PARAMETER LogPath
Path where log file will be created
.EXAMPLE
.\FreeUpOneDriveSpace.ps1 -ExcludeFolders "Documents,Desktop" -MinimumAge 30
#>
param(
[string]$ExcludeFolders = "",
[int]$MinimumAge = 0,
[string]$LogPath = "$env:TEMP\OneDriveFreeUpLog.txt"
)
function Write-Log {
param (
[string]$Message
)
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
"$timestamp - $Message" | Out-File -FilePath $LogPath -Append
}
# Start logging
Write-Log "Script started"
Write-Log "Parameters: ExcludeFolders='$ExcludeFolders', MinimumAge=$MinimumAge days"
try {
# Get the OneDrive path dynamically
# First try OneDrive for Business path
try {
$oneDrivePath = Get-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\OneDrive\Accounts\Business1" -Name "UserFolder" -ErrorAction Stop |
Select-Object -ExpandProperty "UserFolder"
Write-Log "Found OneDrive for Business path: $oneDrivePath"
}
catch {
# Fall back to personal OneDrive path
$oneDrivePath = [Environment]::GetFolderPath("UserProfile") + "\OneDrive"
Write-Log "Using default OneDrive path: $oneDrivePath"
}
# Verify OneDrive path exists
if (-not (Test-Path $oneDrivePath)) {
Write-Log "ERROR: OneDrive path not found at: $oneDrivePath"
throw "OneDrive path not found. Script cannot continue."
}
# Parse excluded folders
$excludedFoldersList = @()
if ($ExcludeFolders -ne "") {
$excludedFoldersList = $ExcludeFolders -split ','
foreach ($folder in $excludedFoldersList) {
Write-Log "Will exclude folder: $folder"
}
}
# Calculate cutoff date for file age
$cutoffDate = (Get-Date).AddDays(-$MinimumAge)
Write-Log "Only processing files last modified before: $cutoffDate"
# Get all files in OneDrive
$files = Get-ChildItem -Path $oneDrivePath -Recurse -File -ErrorAction SilentlyContinue
Write-Log "Found $($files.Count) total files in OneDrive"
$processedCount = 0
$skippedAgeCount = 0
$skippedFolderCount = 0
$alreadyOnlineCount = 0
$convertedCount = 0
foreach ($file in $files) {
$processedCount++
$shouldProcess = $true
# Check if file is in excluded folder
foreach ($excludedFolder in $excludedFoldersList) {
if ($file.FullName -like "*\$excludedFolder\*") {
$shouldProcess = $false
$skippedFolderCount++
if ($processedCount % 100 -eq 0) {
Write-Log "Skipping file in excluded folder: $($file.FullName)"
}
break
}
}
# Check file age
if ($shouldProcess -and $MinimumAge -gt 0) {
if ($file.LastWriteTime -gt $cutoffDate) {
$shouldProcess = $false
$skippedAgeCount++
if ($processedCount % 100 -eq 0) {
Write-Log "Skipping file due to age criteria: $($file.FullName)"
}
}
}
# Process file if it passes all criteria
if ($shouldProcess) {
# Check if file is already online-only
$attributes = [System.IO.FileAttributes]::SparseFile
if ($file.Attributes -band $attributes) {
$alreadyOnlineCount++
if ($processedCount % 100 -eq 0) {
Write-Log "File already online-only: $($file.FullName)"
}
}
else {
try {
# Set file to online-only mode
attrib.exe +U -P $file.FullName | Out-Null
$convertedCount++
if ($processedCount % 100 -eq 0 -or $convertedCount % 20 -eq 0) {
Write-Log "Converted to online-only: $($file.FullName)"
}
}
catch {
Write-Log "ERROR converting file: $($file.FullName). Error: $_"
}
}
}
# Provide progress update for large folders
if ($processedCount % 500 -eq 0) {
Write-Log "Progress: Processed $processedCount of $($files.Count) files"
}
}
# Log summary
Write-Log "--- SUMMARY ---"
Write-Log "Total files processed: $processedCount"
Write-Log "Files already online-only: $alreadyOnlineCount"
Write-Log "Files skipped (excluded folders): $skippedFolderCount"
Write-Log "Files skipped (too recent): $skippedAgeCount"
Write-Log "Files converted to online-only: $convertedCount"
Write-Log "Script completed successfully"
}
catch {
Write-Log "CRITICAL ERROR: $_"
Write-Log "Script terminated with errors"
throw $_
}
Add to SCCM as an application.
The installation program
you can change the excluded folders or the minimum age.
The log file is located in the users temp location.
This is usually c:\users\<userid>\appdata\local\temp
powershell.exe -ExecutionPolicy Bypass -File "FreeUpOneDriveSpace.ps1" -ExcludeFolders "Documents, Desktop" -MinimumAge 14
The Detection method as vbs script
Dim objFSO, objShell, objEnv, tempPath, filePath
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objEnv = objShell.Environment("Process")
tempPath = objEnv("TEMP")
filePath = tempPath & "\OneDriveFreeUpLog.txt"
If objFSO.FileExists(filePath) Then
WScript.echo "installed"
WScript.Quit(0) ' File exists, detection passes
Else
WScript.Quit(0) ' File does not exist, detection fails
End If
User Experience
Install behavior: Install for User
Comments