File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
Modules/CIPPCore/Public/Alerts Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ function Get-CIPPAlertOneDriveQuota {
2+ <#
3+ . FUNCTIONALITY
4+ Entrypoint
5+ #>
6+ [CmdletBinding ()]
7+ Param (
8+ [Parameter (Mandatory )]
9+ $TenantFilter ,
10+ [Alias (' input' )]
11+ [ValidateRange (0 , 100 )]
12+ [int ]$InputValue = 90
13+ )
14+
15+ try {
16+ $Usage = New-GraphGetRequest - tenantid $TenantFilter - uri " https://graph.microsoft.com/beta/reports/getOneDriveUsageAccountDetail(period='D7')?`$ format=application/json&`$ top=999" - AsApp $true
17+ if (! $Usage ) {
18+ Write-AlertMessage - tenant $ ($TenantFilter ) - message " OneDrive quota Alert: Unable to get OneDrive usage: Error occurred: No data returned from API."
19+ return
20+ }
21+ }
22+ catch {
23+ $ErrorMessage = Get-NormalizedError - Message $_.Exception.Message
24+ Write-AlertMessage - tenant $ ($TenantFilter ) - message " OneDrive quota Alert: Unable to get OneDrive usage: Error occurred: $ErrorMessage "
25+ return
26+ }
27+
28+ # Check if the OneDrive quota is over the threshold
29+ $OverQuota = $Usage | ForEach-Object {
30+ if ($_.StorageUsedInBytes -eq 0 -or $_.storageAllocatedInBytes -eq 0 ) { return }
31+ try {
32+ $UsagePercent = [math ]::Round(($_.storageUsedInBytes / $_.storageAllocatedInBytes ) * 100 )
33+ } catch { $UsagePercent = 100 }
34+
35+ if ($UsagePercent -gt $InputValue ) {
36+ $GBLeft = [math ]::Round(($_.storageAllocatedInBytes - $_.storageUsedInBytes ) / 1 GB )
37+ " $ ( $_.ownerPrincipalName ) : OneDrive is $UsagePercent % full. OneDrive has $ ( $GBLeft ) GB storage left"
38+ }
39+
40+ }
41+
42+ # If the quota is over the threshold, send an alert
43+ if ($OverQuota ) {
44+ Write-AlertTrace - cmdletName $MyInvocation.MyCommand - tenantFilter $TenantFilter - data $OverQuota
45+ }
46+ }
You can’t perform that action at this time.
0 commit comments