En tant qu’administrateur Office 365, il est utile de pouvoir piloter l’évolution des volumétries occupées par les environnements SharePoint.
En effet, la somme de tous les volumes utilisés dans les collections SharePoint se retrouve dans le Quota défini pour le tenant, de ce fait, il convient de s’assurer qu’un mauvais usage ne vous crée pas de soucis pour l’ensemble des autres sites.
Ce script permet donc d’utiliser le système des alertes de quota qui sont envoyées au Site Collection Admins en cas de limite atteinte. Ceci afin d’éviter de recevoir des plaintes provenant des utilisateurs des sites en question.
Vous pouvez facilement modifier ce script pour l’adapter à votre cas d’usage.
[string]$username = "adminaccount@tenant.onmicrosoft.com"
[string]$PwdTXTPath = "C:\SECUREDPWD\ExportedPWD-$($username).txt"
[string]$ExportAllUserLogin = ""[double]$QuotaAlertPercentValue = 0.9 # 90%
[integer]$QuotaStorageAlertToApply = 0function Load-DLLandAssemblies
{
[string]$defaultDLLPath = ""# Load assemblies to PowerShell session
$defaultDLLPath = "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.dll"
[System.Reflection.Assembly]::LoadFile($defaultDLLPath)$defaultDLLPath = "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.Runtime.dll"
[System.Reflection.Assembly]::LoadFile($defaultDLLPath)$defaultDLLPath = "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.Online.SharePoint.Client.Tenant.dll"
[System.Reflection.Assembly]::LoadFile($defaultDLLPath)
}
cls
Write-Host " ------------------------------------------------------------ "
write-Host " "
write-Host " Reset the quota alert with $($QuotaAlertPercentValue) "
write-Host " "
Write-Host " ----------------------------------------------------------- "Load-DLLandAssemblies
$secureStringPwd = ConvertTo-SecureString -string (Get-Content $PwdTXTPath)
$adminCreds = New-Object System.Management.Automation.PSCredential $username, $secureStringPwdConnect-SPOService -Url https://tenant-admin.sharepoint.com -credential $adminCreds -ErrorAction SilentlyContinue -ErrorVariable Err
#Retrieve all site collection infos
$sitesInfo = Get-SPOSite -Template "STS#0" -Limit ALL | Sort-Object -Property url | Select *
# Other filtering samples
#$sitesInfo = Get-SPOSite -Filter {Url -like '*tenant.sharepoint.com/sites/ca*' } -Template "STS#0" -Limit ALL | Sort-Object -Property url | Select *
#$sitesInfo = Get-SPOSite -Filter {Url -like '*sgs.sharepoint.com/sites/ca-*' } -Template "STS#0" -Limit ALL | Sort-Object -Property url | Select -first 1 *[int]$i = 1;
[int]$ItemsChanged = 0;Write-Host " >>>> Number of sites found:", $sitesinfo.count
foreach ($site in $sitesInfo)
{
Write-Host " >>>> Site Num to check:", $i -foregroundcolor green
$QuotaStorageAlertToApply = [convert]::ToInt32($site.StorageQuota, 10)
Write-Host " ===>> Storage Quota before the percentage:", $QuotaStorageAlertToApply, "- StorageQuotaAlertPercent:", $QuotaAlertPercentValue -foregroundcolor yellow
$QuotaStorageAlertToApply = $($QuotaStorageAlertToApply * $QuotaAlertPercentValue)
Write-Host " ===>> Storage Quota before round command:", $QuotaStorageAlertToApply -foregroundcolor yellow$QuotaStorageAlertToApply = [math]::Round($QuotaStorageAlertToApply)
Write-Host " >>> Site details:", $site.Url , "- Current Size:", $site.StorageUsageCurrent, "- Storage Quota:", $site.StorageQuota -foregroundcolor green
Write-Host " ===>> Storage Quota Warning Applied:", $site.StorageQuotaWarningLevel -foregroundcolor yellow
Write-Host " ===>> Storage Quota Warning Theoric:", $QuotaStorageAlertToApply -foregroundcolor yellow
if($QuotaStorageAlertToApply -ne $site.StorageQuotaWarningLevel)
{
$ItemsChanged++;
Write-Host " >>>> Number of sites changed:", $ItemsChanged -foregroundcolor green
if ($site.Status -ne "Active")
{
do
{
$site = Get-SPOSite -Identity $site.Url
Write-Host " ===>> Wait 60 sec for the change application" -foregroundcolor red
start-sleep -s 60
}
until ($site.Status -eq "Active")
}
Set-SPOSite -Identity $site.Url -StorageQuotaWarningLevel $QuotaStorageAlertToApply
Write-Host " =======>> Storage Quota Warning Applied:", $QuotaStorageAlertToApply -foregroundcolor yellow
}
else
{
Write-Host " =======>> NO NEED TO CHANGE Storage Quota Warning " -foregroundcolor red
}
$i++;
}Write-Host " ------------------------------------------------------------------------------------------"
Write-Host " >>>> Number of sites modified:", $ItemsChanged, "- of Total sites checked:", $i -foregroundcolor Red
Fabrice Romelard
Commentaires
Enregistrer un commentaire