Today, I am writing about SharePoint Online Automation script for checking the Site Quota. SharePoint Online or Office 365 Automation provides powerful proficiencies to automate the tasks with SharePoint online so as to reduce human efforts and errors as well.
In this post, I will cover a scenario where you connect to SharePoint Online using SharePoint Online PowerShell Management and display the list of all provisioned site collection URLs and Site Quota for an Office 365 tenant. This post is mainly geared towards getting you started with SharePoint Online or Office 365 Automation. Once prepared with this knowledge, you can repeat the tasks easily and hassle-free.
Prerequisites
First, we need to have an Office 365 subscription and SharePoint Online Management installed on your local system. If you don't already have them, you may want to register for the free trial version of Office 365. I also recommend reading the below articles before you start with this demonstration.
- http://www.c-sharpcorner.com/blogs/overview-for-sharepoint-online-management-shell
- https://docs.microsoft.com/en-us/office365/enterprise/powershell/getting-started-with-office-365-powershell
Given below is the step by step solution with screenshots.
Open SharePoint ISE with Admin account and enter the following script.
- Import - Module Microsoft.Online.SharePoint.Powershell
- $UserName = "Global account"
- $Password = Your Password '
- $UsagePercentagelimit = "1"
- #Hash Table to hold results
- $groups = @ {}
- #Setup Credentials to connect
- $Credentials = New - Object System.Management.Automation.PSCredential($UserName, (ConvertTo - SecureString $Password - AsPlainText - Force))
- # Connect - MsolService - Credential $Credentials
- Connect - SPOService - Url "https://spsolutiontips-admin.sharepoint.com/" - Credential $Credentials
- foreach($spoSite in (Get - SPOSite - Limit all - IncludePersonalSite: $false)) {
- $groups.Add($spoSite.Url, @ {})
- $StorageGB = [System.Math]::Round(($spoSite.StorageUsageCurrent / 1024), 2)
- $QuotaGB = ($spoSite.StorageQuota / 1024)
- $groups[$spoSite.Url].Add("QuotaGB", $QuotaGB)
- $groups[$spoSite.Url].Add("StorageGB", $StorageGB)
- if ($QuotaGB - eq 0) {
- $UsagePercentage = [math]::Round($StorageGB, 2) * 100
- } else {
- $UsagePercentage = [System.Math]::Round(($spoSite.StorageUsageCurrent / $spoSite.StorageQuota) * 100, 2)
- }
- $groups[$spoSite.Url].Add("Size", $spoSite.StorageUsageCurrent)
- $groups[$spoSite.Url].Add("UsagePercentage", $UsagePercentage)
- }
- $exp = @("Url,Storage USed,Storage Limit,Percentage Used %,")
- Foreach($g in $groups.keys) {
- if ($($groups[$g]["UsagePercentage"]) - ge $UsagePercentagelimit) {
- $exp += ("$($g)", "$($groups[$g]["
- StorageGB "])", "$($groups[$g]["
- QuotaGB "])", "$($groups[$g]["
- UsagePercentage "])" - join ",")
- }
- }
- $exp | Out - File "C:\testing\Quota.csv" - Encoding ascii - Force


Join the conversation! Your thoughts help the community grow.