PowerShell – change the storage space for a specific user’s OneDrive

1+

As an admin you can easily make an adjustment of a OneDrive storage limit for all users through a OneDrive admin center. If you need to do the same for a specific user, here is a Microsoft article that describes that – https://docs.microsoft.com/en-us/onedrive/change-user-storage

Truth is, it only takes a single line of code to make an adjustment; however, my script below takes care of most little things, requirements, and inconveniences:

  • you only need an email address of a user;
  • the minimum size of allocated space is 1 GB;
  • the maximum size is 5 TB.
$email = Read-Host "Please provide an email address of the user"

$convertedemail = $email -replace "\.","_" -replace "@","_"

$partofthelink = "-my.sharepoint.com/personal/" + $convertedemail

$onedriveurl = Get-SPOSite -IncludePersonalSite $true -Limit all -Filter "Url -like $partofthelink"

$onedriveurl

Do {
    Try {
        $num = $true
		[int]$sizegb = Read-Host "Please specify the size of OneDrive storage space to be set (ranging from 1 GB to 5120 GB)"
	} # end try
    Catch {$num = $false}
} # end do 
Until (($sizegb -gt 0 -and $sizegb -le 5120) -and $num -eq $true)

$sizemb = [int]$sizegb * 1024

Set-SPOSite -Identity $onedriveurl[0].Url -StorageQuota $sizemb

Write-host "OneDrive storage space for $email has been successfully changed to $sizegb GB"
1+

Leave a Reply

Close Menu