Update site collection quotas in SharePoint Online with PowerShell

Many articles have been posted about how to do this onprem, but i was looking around last week and didn’t see anyone sharing the technique to do this in SharePoint Online.

Every site collection in  SharePoint Online can be configured with a quota, but how do you know which ones are running out of space.  This script will let you automatically resize any that are running out of space by finding all site collections that are using 75% of their quota and doubling the site of the current quota.  This may not be the right numbers for your environment but i hope this sample gets you on off and running quickly.

 

#you’ll need the msonline service module to connecto to spo
import-module MSOnline

Resize.ps1

#import common functions
. “C:\mypath\functions.ps1”
#### configuration information

$baseFilePath = “C:\mypath\”

$tenantName = “mytenant

$userName = “my upn goes here

# this uses a custom function in the functions.ps1 files
$msolcred = Get-StoredCredential -UserName $userName -BasePath $baseFilePath

# this uses a custom function in the functions.ps1 files
$adminSite = Get-AdminSiteUrl $tenantName
Connect-SPOService –Url $adminSite  -credential $msolcred

# this will get all sites and limit to only those that are 75% of the way to their quota
$sites = Microsoft.Online.SharePoint.PowerShell\Get-SPOSite  -Limit ALL -Detailed |Where {($_.StorageUsageCurrent / $_.StorageQuota) -gt .75} |  Select URL, StorageQuota, StorageUsageCurrent, StorageQuotaWarningLevel, StorageQuotaType, Status
foreach($site in $sites){

Write-Output (“Site: ” + $site.Url + ” Usage:” + $site.StorageUsageCurrent + ” Quota:” + $site.StorageQuota + ” Warning Level:” + $site.StorageQuotaWarningLevel)

        # this will set the quota to double it’s current size, feel free to tweak to your needs
Microsoft.Online.SharePoint.PowerShell\Set-SPOSite -Identity $site.Url -StorageQuota ($site.StorageQuota*2)

}

 

Functions.ps1

Function Get-StoredCredential
{
param( [string]$UserName, [string]$BasePath)

 

$File = $baseFilePath + “password.txt”
$FileContent = Get-Content $File
return New-Object -TypeName System.Management.Automation.PSCredential ` -ArgumentList $UserName, ($FileContent | ConvertTo-SecureString)
}
Function Get-AdminSiteUrl
{
param([string]$TenantName)

return “https://” + $tenantName + “-admin.sharepoint.com”
}