当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] SharePoint Online:使用 PowerShell 监视网站集存储使用情况

作者:精品下载站 日期:2024-12-14 15:55:35 浏览:15 分类:玩电脑

SharePoint Online:使用 PowerShell 监视网站集存储使用情况


要求:监视 SharePoint Online 存储指标并发送有关当前使用情况的电子邮件。

SharePoint Online:使用 PowerShell 生成存储使用情况报告

默认情况下,SharePoint Online 存储管理设置为“自动”,所有存储分配均从中央存储池自动管理。但是,在您的环境中,如果存储管理选项设置为“手动”来微调分配给每个站点的存储空间,那么最好设置一封警报电子邮件,以便在站点接近限制时通知您。存储限制以确保它们不会影响站点性能。

尽管您可以从 Microsoft 365 使用情况报告、SharePoint 网站的存储指标页面或 SharePoint Online 管理中心检查存储消耗,但让我们自动化该过程!生成存储指标报告并使用 PowerShell 向 SharePoint 管理员发送电子邮件。


#Set Parameters
$AdminCenterURL="https://crescent-admin.sharepoint.com"
$AdminUserName = "[email protected]"
$AdminPassword = "Password Goes here"
$EmailFrom = "[email protected]"

#Prepare the Credentials
$SecurePassword = ConvertTo-SecureString $AdminPassword -AsPlainText -Force
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminUserName, $SecurePassword
  
#Connect to SharePoint Online
Connect-SPOService -url $AdminCenterURL -Credential $Credential

#Get All Site Collections Site Storage Usage
[string]$SiteStorage = Get-SPOSite -Limit All | Select Title, URL, StorageQuota, StorageUsageCurrent, @{Label="Percentage";Expression={[math]::Round( ($_.StorageUsageCurrent / $_.StorageQuota * 100),2)}} | ConvertTo-Html

#Send Email
Send-MailMessage -From $EmailFrom -To $AdminUserName -Subject "Storage Report" -Body $SiteStorage -BodyAsHtml -smtpserver "smtp.office365.com" -usessl -Credential $Credential -Port 587

PnP PowerShell 用于监视站点存储和发送电子邮件

当站点达到特定警告级别时,通常每周都会发送内置存储配额警告电子邮件。但是,这些电子邮件可能为时已晚,网站可能会达到最大存储限制并在网站管理员收到警报电子邮件之前设置为只读。因此,这是用于监视存储使用情况并发送警报电子邮件的 PnP PowerShell 脚本。


#Set Variables
$TenantAdminURL = "https://crescent-admin.sharepoint.com"
$EmailTo = "[email protected]"
$AdminUserName = "[email protected]"
$AdminPassword = "Password goes here"

#Prepare the Credentials
$SecurePassword = ConvertTo-SecureString $AdminPassword -AsPlainText -Force
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminUserName, $SecurePassword
 
#Connect to PnP Online
Connect-PnPOnline -Url $TenantAdminURL -Credentials $Credential

$CSSStyle = "<style>
table {font-family: Arial, Helvetica, sans-serif; border-collapse: collapse; width: 100%;}
table td, th {border: 1px solid #ddd; padding: 8px;}
table tr:nth-child(even){background-color: #f2f2f2;}
table tr:hover {background-color: #ddd;}
table th { padding-top: 12px; padding-bottom: 12px; text-align: left; background-color: #4CAF50; color: white;}
</style>"

#Get the Site collection Storage details
[string]$EmailBody = Get-PnPTenantSite | Select @{Label="Title";Expression={$_.Title}}, 
                                        @{Label="URL";Expression={$_.URL}}, 
                                        @{Label="Allocated";Expression={$_.StorageMaximumLevel}}, 
                                        @{Label="Used";Expression={$_.StorageUsage}}, 
                                        @{Label="Percentage";Expression={[math]::Round( ($_.StorageUsage/$_.StorageMaximumLevel*100),2)}} | 
ConvertTo-Html -Title "Crescent Inc. Storage Report" -Head $CSSStyle -PreContent "Sites Storage Report"

#Send Email
Send-PnPMail -To $EmailTo -Subject "Storage Report" -Body $EmailBody

这是正在运行的脚本:

[玩转系统] SharePoint Online:使用 PowerShell 监视网站集存储使用情况

请注意,虽然我在脚本中使用了纯密码,但推荐的方法是使用 App ID - App Secret 在 SharePoint Online 中进行身份验证!对于SharePoint Online Management Shell,您可以使用加密的密码文件!脚本准备就绪后,您可以使用 Windows 任务计划程序或 Azure 自动化将其安排为每天运行一次。

当网站超过阈值时收到警报电子邮件

如果您只想在站点的存储消耗超过特定阈值时收到通知,该怎么办?假设您希望在站点达到分配存储空间的 90% 时收到警报电子邮件。


#Set Variables
$TenantAdminURL = "https://crescent-admin.sharepoint.com"
$EmailTo = "[email protected]"
$AdminUserName = "[email protected]"
$AdminPassword = "Password goes here"
$PercentageThreshold = 90

#Prepare the Credentials
$SecurePassword = ConvertTo-SecureString $AdminPassword -AsPlainText -Force
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminUserName, $SecurePassword
 
#Connect to PnP Online
Connect-PnPOnline -Url $TenantAdminURL -Credentials $Credential

$CSSStyle = "<style>
table {font-family: Arial, Helvetica, sans-serif; border-collapse: collapse; width: 100%;}
table td, th {border: 1px solid #ddd; padding: 8px;}
table tr:nth-child(even){background-color: #f2f2f2;}
table tr:hover {background-color: #ddd;}
table th { padding-top: 12px; padding-bottom: 12px; text-align: left; background-color: #4CAF50; color: white;}
</style>"

#Collect Site usage data
$SiteStorageData = @()
ForEach($Site in (Get-PnPTenantSite))
{
    $SiteStorageData += New-Object PSObject -Property ([ordered]@{
        Title  = $Site.Title
        URL = $Site.URL
        Allocated = $Site.StorageMaximumLevel
        Used = $Site.StorageUsage
        Percentage = [math]::Round( ($Site.StorageUsage/$Site.StorageMaximumLevel*100),2)
    })
}
#Filter Sites with usage percentage exceeding given threshold
$SitesExceeding = $SiteStorageData | Where {$_.Percentage -gt $PercentageThreshold}
If($SitesExceeding -ne $Null)
{
    [string]$EmailBody = $SitesExceeding | ConvertTo-Html -Title "Crescent Inc. Storage Report" -Head $CSSStyle -PreContent "Sites Storage Report"
    #Send Email
    Send-PnPMail -To $EmailTo -Subject "Storage Report" -Body $EmailBody
}

这是关于生成网站存储报告的另一篇文章:SharePoint Online:使用 PowerShell 的网站集存储使用情况报告

结论

总之,监视 SharePoint Online 中的存储使用情况对于确保您的网站集具有足够的存储容量来满足组织的需求非常重要。有多种方法可用于监视 SharePoint Online 中的存储使用情况,包括存储指标页面、PowerShell 和 Office 365 管理中心。

通过定期监控 SharePoint Online 中的存储使用情况,您可以主动规划额外的存储需求、优化存储的使用并避免存储容量耗尽。我希望本教程有助于解释如何监视 SharePoint Online 中的存储使用情况。

经常问的问题:

当超过 SharePoint 存储限制时会发生什么?

当您超过 SharePoint 存储限制时,您将在 SharePoint 网站上收到一条错误消息,指示您的存储内容已超出限制。超过限制后,您仍然可以上传文件,但不能修改内容或权限。您可以调整存储配额或购买额外存储来解决问题!

SharePoint Online 中的存储限制是多少?

SharePoint Online 的存储限制因您的计划而异。例如,Office 365 Business Essentials 和 Business Premium 计划的存储限制为每个组织 1 TB 加上每个购买的许可证 10 GB。 Enterprise E1、E3 和 E5 计划的存储限制为每个用户 1 TB。

SharePoint Online 中每个网站集的最大存储容量是多少?

SharePoint Online 中每个网站集的最大存储容量为 25 TB!

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯