Office 365 SharePoint Online Admin PowerShell Cmdlet – With Samples


Office 365 and SharePoint Online is an ever growing and evolving cloud service  from Microsoft and in the migration to wave 15 of the Office product, Microsoft have released a set of PowerShell commands to manage your SharePoint Admin console.

Its important to note that these PowerShell commands are not the normal PowerShell commands you get for on-premise SharePoint and they are here to manage creating and managing site collection as well as gather information about your tenancy.


You can download the powershell commands from here

Here are a few powershell commands that you might find useful.

Import SharePoint Online Module

Import-Module Microsoft.Online.SharePoint.Powershell

Use this cmdlet to add the commands for SHarePoint Online management shell

Connection to SharePoint Online

We are first going to set the URL of the SharePoint Online Admin site and then log in.

Note we only have powershell for the admin portal so you have to connect to the – URL.

$spourl = “”

connect-sposervice -url $spourl


List all Site Collections


Get current storage of site collection

First we are going to get the Site Collection and request the information the current storage usage.

$spositecollection = get-sposite


Average out Storage Quota to all Site Collections

This last command is a little bit more complicated.

We are going to get the storage quota for the tenancy and then divide that by the number of site collections we have an implement it to each site.  This command can take a while to run as it will run on each site collection, confirm and then move onto the next one.

#Gets the number of sites

$getnumberofsites = Get-SPOSite

$numbersofsites = $getnumberofsites.count


#get the storage quota for your tenancy

$gettenancy = Get-SPOTenant

$storagequota = $gettenancy.StorageQuota


#set average

$average = $storagequota / $numbersofsites

Get-SPOSite | foreach {Set-SPOSite -Identity $_.Url -StorageQuota $average}

This will now set each site collection to the average of the tenancy storage quota.  It will error if the average is over 100GB as this is the highest it can be.

5 thoughts on “Office 365 SharePoint Online Admin PowerShell Cmdlet – With Samples

    • A Pearce

      I would interested in hearing your experience as I haven’t seen any issues with Wave 15 and if anything they added more features with the tenancy is the wave 15 level.

  1. diany

    Hi Alex,

    Do you know if there is an option to get the document library size and # items for all users on SharePoint Online using powershell?


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.