Power Community

Power Community

Receive the available storage within your SharePoint Online tenant

Within the SharePoint admin centre there is that little detail telling you how much storage you have available out of your total storage. But how do you get that without visiting the SharePoint Admin Centre every day?

SharePoint list with document to be approved
SharePoint list with document to be approved

Retrieve the available storage using PowerShell

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.

Create an Azure Automation Account

So I click on the Create option and then complete the following form:

Receive the available storage within your SharePoint Online tenant Microsoft 365 image 3

After a while my Automation Account will be ready.

Receive the available storage within your SharePoint Online tenant Microsoft 365 image 4

In the left hand navigation there is an option for the Runbook to be created:

Receive the available storage within your SharePoint Online tenant Microsoft 365 image 5

I’m going to ignore the example runbooks and I’m creating a new runbook as shown below

Receive the available storage within your SharePoint Online tenant Microsoft 365 image 12

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.

System.Management.Automation.CommandNotFoundException

In your Automation Account you can install the required module.

In our case we need Microsoft.Online.SharePoint.PowerShell

Receive the available storage within your SharePoint Online tenant Microsoft 365 image 9

This is all quite easy as you can select the module that we need from the Gallery.

Receive the available storage within your SharePoint Online tenant Microsoft 365 image 10

Please note that it can take a while for the module to be imported.

Receive the available storage within your SharePoint Online tenant Microsoft 365 image 11

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 moduels 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:

Receive the available storage within your SharePoint Online tenant Microsoft 365 image 13

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

We will now see the following result returned by the Runbook.

Receive the available storage within your SharePoint Online tenant Microsoft 365 image 14

Email the result

Ok, there will be a number of options available, but I’m going to use Power Auotmate to send out the email.

Receive the available storage within your SharePoint Online tenant Microsoft 365 image 15

Then we get the output from the job that we created, before we send an email.

Receive the available storage within your SharePoint Online tenant Microsoft 365 image 16

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.

Receive the available storage within your SharePoint Online tenant Microsoft 365 image 17

This post was originally published on this site

- Advertisement -spot_img

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement - Advertisement

Latest News

Preferred Solution | New feature | Microsoft Dataverse

Click on the below image to navigate to my YouTube Channel. Please like and share your valuable feedback on this...

More Articles Like This

- Advertisement -spot_img