Script for Auto-Adjusting Site quotas in SharePoint Online / O365 based on current useage

** IMPORTANT UPDATE #2 -this is no longer needed.

As of September 2015, Site Quotas are no longer needed!

The screenshot below came from our tenant settings screen – Set it to Automatic and forget about site quotas!



If you use the script below, you may want to put in a filter to prevent the script from working on any site with the managed path of /portals/


Microsoft recently added Video portals to office 365.

Ours was added this morning.

I looked at it in the admin screen because I was curious what site collections had been created.

I noticed something peculiar: The Storage Quota was 0.


You can’t set a quota to zero. Not in the UI, not in PowerShell.

Well tonight my script ran and guess what, it reset my quote on the Video portal.

Originally, Video portal storage was supposed to come out of the overall SPOnline allotment, so this may not be a big deal, maybe we needed to set it anyways?

But, since it’s not possible to set zero manually, I wonder if this was one site you didn’t have to manage/pre-allocate storage too? Or maybe MS decided to make storage unlimited?

I’m not really sure, but in the short term, I thought I’d best warn people that there are some unknowns here as it relates to using the below script with Office Video.


AND NOW BACK TO OUR ORIGINAL ARTICLE, as it was published on April 15th:

The year is 2015, You’ve just been given “TONS” of storage on SharePoint online, and someone says “Lets give everyone a 200GB site quota”.

Seems like a great idea, you’ll never run out of space, so why not set the limit high?

Well, it turns out, the word “Quota” has a different meaning in SharePoint Online / Office 365 than it did in SP on Premise.

In the On Premise version of SharePoint, the quota was a limit.
In SharePoint Online, it’s an Allocation.

What’s the difference you ask?

Say you have a 1000GB of storage on SharePoint on premise.

With On premise SharePoint, you can allocate a 200gb quota to 10 sites, “over committing” what you actually have. It works because space isn’t ‘reserved’ for that site, it’s just a limit. You’re telling on premise sharepoint “Don’t let any site get bigger than 200gb”.

Take a similar situation on SharePoint Online:

Say you have 1000GB of storage on SPO

You can only allocate 200GB quotas 5 times – each time you do, your total available drops by 200GB so by the 5th one, you have nothing left to give. This is true, even if the sites are empty!

So SharePoint online works a little differently, at least in 2015 it does – maybe one day this article won’t be relevant, but it is today.

What are we to do if we want to give users basically unlimited sized site collections

Now the question: What are we to do if we want to give users basically unlimited sized site collections, but we can’t allocate large numbers to EACH site collection?

Well, here’s what I did – I wrote a script that looks at how much storage each site collection is using, then adjusts it so there is a certain amount of ‘headroom’.

I run the script daily via a scheduled task.

I also have another script that sets up the connection to SharePoint Online which runs first, if you need that part, it’s elsewhere on this site.

The logic is fairly straightforward, but lets do an example:

All sites should be 4GB or more over the size used:

  • An empty site would have 4gb allocated
  • A site using 3gb would have 7gb allocated
  • A site using 10gb would have 14gb allocated.

Make sense?

That logic is pretty simple, take the size of the site, add 4gb to it, that’s it’s allocation.

For performance reasons, it would be great if we weren’t constantly adjusting each and every site, every time we run the script, the $slack setting helps with that.

Here’s the script:

(If you need help scheduling a task, I have a blog post and video here about that. )

write-host "Be sure to connect to SPO first" -foregroundcolor yellow

$headroom = 4000;
$slack = 500;

#this could really be one line, but it's broken out into two for readability
#first, we get all the sites that we need to change the quota for.
# we do this by the formula Site size must be > the quota, minus the headroom
# now if we just did this, we'd likely have to increase every site every time. so we also factor in a slack amount.
#if the desired headroom is say 4000, we'll allow the site to come within 3500 of being full, then make an adjustment to 
# ensure we have 4000 free.

#this first line gets the list of sites we need to work with
$sites = get-sposite -detailed | where {$_.StorageUsageCurrent -gt $($_.StorageQuota - $headroom + $slack)}

#this lets us see what we're doing...
write-host "$($sites.count) sites to work on"
foreach ($site in $sites)
 write-host "$($site.url) : $($site.StorageUsageCurrent) of $($site.StorageQuota)"

#This line allocates the storage quota, based on the storage in use
#this was timing out
#$sites | set-sposite -StorageQuota $($_.StorageUsageCurrent + $headroom)
foreach ($site in $sites)
 $newquota = $site.StorageUsageCurrent + $headroom
 write-host "altering: $($Site.url) used: $($site.StorageUsageCurrent), old Quota: $($site.StorageQuota), new Quota: $newquota"
 $site | set-sposite -StorageQuota $newquota

write-host "Done"

– Jack

Leave a Reply