Microsoft cloud engineer - SharePoint, Office 365, Azure, DotNet, Angular, JavaScript.
Microsoft cloud engineer - SharePoint, Office 365, Azure, DotNet, Angular, JavaScript.

Office 365 – Monitor site collection storage (PS1 daily email)

I wrote the below PowerShell script to gather site collection storage data for any Office 365 tenant.  This PS1 could be scheduled daily for a quick email to keep an eye on sites approaching storage limits.

Hope this helps! 

shades_smile

 

5-18-2015 8-47-11 PM
# Plugin
Import-Module Microsoft.Online.SharePoint.PowerShell -ErrorAction SilentlyContinue
# Config -- get URL from "Tenant Admin" page in Office 365
$url	= "https://company-admin.sharepoint.com"
$user	= "admin@company.com"
$smtp	= "mailrelay"
# Connect
Connect-SPOService -url $url -credential $user
# Gather data
$sites = Get-SPOSite -Detailed
$coll = @()
foreach ($s in $sites) {
	$curr = $s.StorageUsageCurrent
	$quota = $s.StorageQuota
	if ($quota -eq 0) {
		$prct = [math]::Round($curr, 2) * 100
	} else {
		$prct = [math]::Round($curr/$quota, 2) * 100
	}
	$surl = $s.Url
	$coll += New-Object -TypeName PSObject -Prop (@{'curr'=$curr;'quota'=$quota;'prct'=$prct;'surl'=$surl})
}
$coll = $coll | sort prct -Desc
	
# Format HTML
$html = ""
foreach ($c in $coll) {
	$row = "" -f $c.surl, $c.curr, $c.quota, $c.prct
	$html += $row
}
$html += "
URL Current (MB) Quota (MB) Percent
{0} {1} {2} {3} %
 
" # Send email Send-MailMessage -To $user -From $user -Subject "Office 365 Storage" -Body $html -BodyAsHtml -SmtpServer $smtp

© Copyright 2016
@ SPJeff

Return to Top ▲Return to Top ▲