In this blog post I will show you how to set OneDrive quotas with PowerShell. I’d say here we go!
First, let’s connect to SharePoint Online. Make sure you enter the correct URL and the correct user account.
Install-Module -Name Microsoft.Online.SharePoint.PowerShell -Force -AllowClobber
$cred = Get-Credential -Credential patrick@m365ps2022.onmicrosoft.com
Connect-SPOService -Url https://m365ps2022-admin.sharepoint.com -Credential $cred
Next, we need to figure out the URLs.
# Find out all OneDrive URLs
$LogFile = [Environment]::GetFolderPath("Desktop") + "\OneDriveSites.log"
Get-SPOSite -IncludePersonalSite $true -Limit all -Filter "Url -like '-my.sharepoint.com/personal/'" |
Select-Object -ExpandProperty Url | Tee-object -FilePath $LogFile
Write-Host "File saved as $($LogFile)."
Once we have the URL, we can use it to set quotas.
# Configure OneDrive Quota per User
$OneDriveSite = "https://m365ps2022-my.sharepoint.com/personal/f_bizeps_m365ps2022_onmicrosoft_com"
$OneDriveStorageQuota = "2097152" # MB
$OneDriveStorageQuotaWarningLevel = "1000000" # MB
Set-SPOSite -Identity $OneDriveSite -StorageQuota $OneDriveStorageQuota -StorageQuotaWarningLevel $OneDriveStorageQuotaWarningLevel
Write-Host "Done"
That’s it. We now have set a OneDrive quota for a user.
But now we’re getting to the real deal. With the code generated above, we can also set quotas for all users, all at once. This is called automation.
# Automation
$urls = Get-Content $home\desktop\OneDriveSites.log
$OneDriveStorageQuota = "2097152" # MB
$OneDriveStorageQuotaWarningLevel = "1000000" # MB
foreach ($u in $urls) {
Set-SPOSite -Identity $u -StorageQuota $OneDriveStorageQuota -StorageQuotaWarningLevel $OneDriveStorageQuotaWarningLevel
}
That’s what I wanted to show in this post. I hope it was helpful.
Categories: Microsoft 365, PowerShell
1 reply »