Friday, 17 June 2016

Set Storage Quota for Office 365 Group Site using PowerShell

As you know, Office 365 Group is nothing but a hidden site collection that are not visible in Site Collections view in Office 365 Admin portal. You can only access these site collections by using PowerShell or through URL (https://<tanentname>.sharepoint.com/sites/<group-name>/Shared documents”). Since you can't view the site in Office 365 Admin portal, the only way set storage size limit is using Powershell. In this article, I am going to write powershel script to set maximum storage size and storage warning level for Office 365 group site.

We can use the SharePoint Online Powershell cmdlet Set-SPOSite to set storage quota and storage warning size limit. Before proceed, run the following command to connect Sharepoint Online powershell module.
Connect-SPOService -Url https://<tanentname>-admin.sharepoint.com -Credential admin@o365domain.com
Now, run the following script to set storage quota and warning level.
$StorageQuota= 2048 # 2GB or 2048MB
$WarningLevel = 1800 # 1800MB

$siteUrl ="https://<tanentname>.sharepoint.com/sites/<group-name>"
Set-SPOSite -Identity $siteUrl -StorageQuota $StorageQuota -StorageQuotaWarningLevel $WarningLevel

Set Storage Quota for all Office 365 Groups Site:

To set the storage quota for all the Office 365 Groups, first, we need to get sharepoint site url for all the office 365 groups by using Exchange Online cmdlet Get-UnifiedGroup. The following powershell script update storage quota and warning level for all the office 365 groups. You need to replace your own Office 365 tenant name and admin credentials.
$userName ="admin@<tanentname>.onmicrosoft.com" 
$o365Cred = Get-Credential -UserName $userName -Message "Enter Office 365 Admin Credentials"
$o365Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $o365Cred -Authentication Basic -AllowRedirection
Import-PSSession $o365Session

$spoAdminUrl ="https://<tanentname>-admin.sharepoint.com/" 
Connect-SPOService -Url $spoAdminUrl -Credential $o365Cred 

$O365Groups = Get-UnifiedGroup -ResultSize Unlimited

$StorageQuota= 2048 # 2GB or 2048MB
$WarningLevel = 1800 # 1800MB

ForEach ($O365Group in $O365Groups){ 
If($O365Group.SharePointSiteUrl -ne $null) {
$siteUrl = $O365Group.SharePointSiteUrl
Set-SPOSite -Identity $siteUrl -StorageQuota $StorageQuota -StorageQuotaWarningLevel $WarningLevel 
}
}
Once you set the storage quota, you can use the Powershell cmdlet Get-SPOSite to get current storage quota and warning level. The following script list storage quota of all the office 365 groups site.

$O365Groups = Get-UnifiedGroup -ResultSize Unlimited
$CustomResult=@() 
ForEach ($O365Group in $O365Groups){ 
If($O365Group.SharePointSiteUrl -ne $null) 
{ 
   $O365GroupSite=Get-SPOSite -Identity $O365Group.SharePointSiteUrl 
   $CustomResult += [PSCustomObject] @{ 
     GroupName =  $O365Group.DisplayName
     SiteUrl = $O365GroupSite.Url 
     StorageQuota_inGB = $O365GroupSite.StorageQuota/1024
     WarningSize_inGB =  $O365GroupSite.StorageQuotaWarningLevel/1024
     CurrentStorage_inMB = $O365GroupSite.StorageUsageCurrent
  }
}} 
 
$CustomResult | FT

Advertisements
Advertisements

No comments:

Post a Comment