Within the SharePoint admin centre there is that little detailed overview, telling you the available storage out of your total storage. But how do you get that without visiting the SharePoint Admin Centre every day?
Retrieve the available storage using PowerShell
Table of Contents
The PowerShell script to get the storage is actually really simple:
$AdminCenterURL = "https://tenant-admin.sharepoint.com"
Connect-SPOService -Url $AdminCenterURL
Get-SPOGeoStorageQuota
This will return the following data:
GeoLocation : EU
GeoUsedStorageMB : 1886079
GeoAvailableStorageMB : 176769
GeoAllocatedStorageMB : 0
TenantStorageMB : 2062848
QuotaType : Allocated
So how do we get this in an email on a regular basis?
Create an Azure Runbook
I’m going to use an Azure runbook to run my PowerShell. First step is to create an Automation Account.
So I click on the Create option and then complete the following form:
After a while my Automation Account will be ready.
In the left hand navigation there is an option for the Runbook to be created:
I’m going to ignore the example runbooks and I’m creating a new runbook as shown below
Now we can copy in our PowerShell script but if we run the script we will get errors as we haven’t installed the SharePoint Online modules yet.
In your Automation Account you can install the required module.
In our case we need Microsoft.Online.SharePoint.PowerShell
Installing Modules in Automation Accounts
Within the left hand navigation the Modules options gives us all we need.
This is all quite easy as you can select the module that we need from the Gallery.
Please note that it can take a while for the module to be imported.
Once the module is available we can run our script. But we will still need to sort something out. Without the runbook there is no interaction possible. So we will need to sort out the authentication within the script.
You could of course always install the modules as part of your script by adding the following lines:
Install-Module Microsoft.Online.SharePoint.PowerShell -Scope CurrentUser -Force
Import-Module Microsoft.Online.SharePoint.PowerShell
$AdminCenterURL = "https://pieterveenstraMVP-admin.sharepoint.com"
Connect-SPOService -Url $AdminCenterURL
Get-SPOGeoStorageQuota
Now we have just one issue left:
As there is no interaction possible within the Runbook scripts, we will need to connect in a different way.
Credentials stored in the Azure Automation Account
You can store credentials in the Azure Automation Account. And then all we need to do is adjust the Connection-SPOService call as shown below:
Install-Module Microsoft.Online.SharePoint.PowerShell -Scope CurrentUser -Force
Import-Module Microsoft.Online.SharePoint.PowerShell
$AdminCenterURL = "https://pieterveenstraMVP-admin.sharepoint.com"
$creds=Get-AutomationPSCredential -Name 'MyCredentials'
Connect-SPOService -Url $AdminCenterURL -Credential $creds
Get-SPOGeoStorageQuota
Ok, I don’t really like that I can’t use MFA on the account that I specified within the Azure Automation Account, but that is the limitation that we have here.
We will now see the following result returned by the Runbook.
Email the result
Ok, there will be a number of options available, but I’m going to use Power Automate to send out the email.
Then we get the output from the job that we created, before we send an email.
And now we get an email with the following output. We can of course format this a bit better. But I didn’t want to make the Azure Automation script any more complicated as part of this post.