SharePoint Online: รับขนาดพื้นที่เก็บข้อมูลถังรีไซเคิลโดยใช้ PowerShell
ความต้องการ: รับการใช้พื้นที่จัดเก็บถังรีไซเคิลของคอลเลกชันไซต์ SharePoint Online ทั้งหมด
SharePoint Online: ค้นหาขนาดพื้นที่เก็บข้อมูลถังรีไซเคิลของไซต์คอลเลกชัน
คุณสงสัยหรือไม่ว่าถังรีไซเคิล SharePoint Online ของคุณกินพื้นที่เท่าใด ถังรีไซเคิลใน SharePoint Online ช่วยให้คุณสามารถคืนค่าเนื้อหาที่ถูกลบ เช่น รายการ ไลบรารี และเอกสารภายในระยะเวลาที่กำหนด ด้วยเหตุนี้ ถังรีไซเคิลยังใช้พื้นที่จัดเก็บ ซึ่งอาจส่งผลเสียต่อประสิทธิภาพและประสิทธิภาพของสภาพแวดล้อม SharePoint Online ของคุณ
ในโพสต์นี้ เราจะแสดงวิธีตรวจสอบขนาดของถังรีไซเคิลด้วยความช่วยเหลือของ PowerShell!
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Variables for Processing
$SiteUrl = "https://Crescent.sharepoint.com/Sites/Marketing"
#Setup Credentials to connect
$Cred = Get-Credential
Try {
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
#Get the Site collection's recycle bin: both 1st stage and 2nd stage
$RecycleBinItems = $Ctx.Site.RecycleBin
$Ctx.Load($RecycleBinItems)
$Ctx.ExecuteQuery()
#Get Size of the Recycle bin items
$RecycleBinSize = $RecycleBinItems | Measure-Object Size -Sum
Write-Host -f Green "Total Recycle Bin Size: $($RecycleBinSize.Sum/1MB) MB"
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
PowerShell เพื่อรับขนาดพื้นที่เก็บข้อมูลของถังรีไซเคิลของ SharePoint Online
ลองค้นหาขนาดถังรีไซเคิลของไซต์ SharePoint Online ทั้งหมดในผู้เช่าของคุณดูไหม
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.Online.SharePoint.Client.Tenant.dll"
#Function to Get the recycle bin Size of a SharePoint Online site collection
Function Get-SPOSiteRecycleBinSize($SiteURL, $Cred)
{
#Setup credentials
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Set up the context
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Context.Credentials = $Credentials
$Site = $context.Site
$RecycleBin = $Site.RecycleBin
$context.Load($Site)
$context.Load($RecycleBin)
$context.ExecuteQuery()
$FirstStageSize=0
$SecondStageSize=0
Foreach($Item in $RecycleBin)
{
If($Item.itemState -eq "FirstStageRecycleBin")
{
$FirstStageSize+=$Item.Size
}
Else
{
$SecondStageSize+=$Item.Size
}
}
#Output the results
$Data ="Site Collection URL {0}. First Stage Recycle Bin Size {1}. Second Stage Recycle Bin Size {2}" -f $SiteURL,$FirstStageSize,$SecondStageSize
Write-host -f Green $Data
}
#Get All Site collections from the Tenant- Including Modern Team sites and communication sites
Function Get-SPOSites($AdminSiteURL, $Cred)
{
#Setup credentials to connect
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($AdminSiteURL)
$Ctx.Credentials = $Credentials
#Get the tenant object
$Tenant = New-Object Microsoft.Online.SharePoint.TenantAdministration.Tenant($ctx)
#Get All Site Collections
$SiteCollections=$Tenant.GetSitePropertiesFromSharePoint(0,$true)
$Ctx.Load($SiteCollections)
$Ctx.ExecuteQuery()
#Iterate through Each site collection
ForEach($Site in $SiteCollections)
{
Write-host -f Yellow "Searching Site Collection:"$Site.URL
Get-SPOSiteRecycleBinSize -SiteUrl $Site.Url -Cred $Cred
}
}
#Set Parameters
$AdminSiteUrl = "https://crescent-admin.sharepoint.com/"
$Cred= Get-Credential
Get-SPOSites -AdminSiteURL $AdminSiteUrl -Cred $Cred
สคริปต์นี้ทำให้คุณได้รับพื้นที่เก็บข้อมูลที่อยู่ในถังรีไซเคิลระยะแรกและระยะที่สองของคอลเลกชันไซต์ทั้งหมดของผู้เช่า
PnP PowerShell เพื่อรับขนาดถังรีไซเคิลของ SharePoint Online ไซต์คอลเลกชัน
คุณสามารถใช้ Get-PnPRecycleBinItem cmdlet เพื่อดูรายการทั้งหมดในถังรีไซเคิลของไซต์คอลเลกชัน:
#Config Variables
$SiteURL = "https://Crescent.sharepoint.com/sites/marketing"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Sum Recycle bin Items Size
$RecycleBinSize = Get-PnPRecycleBinItem -RowLimit 500000 | Measure-Object -Property Size -Sum
#Get Recycle bin size
Write-host "Recycle Bin Size (MB):" ([Math]::Round($RecycleBinSize.Sum/1MB,2))
สร้างรายงานขนาดถังรีไซเคิลสำหรับไซต์ SharePoint Online ทั้งหมด
ลองค้นหาขนาดถังรีไซเคิลสำหรับไซต์ทั้งหมดในผู้เช่าดูไหม นี่คือสคริปต์ PowerShell:
# Parameters
$AdminCenterURL = "https://Crescent-admin.sharepoint.com"
$OutputPath = "C:\Temp\RecycleBinRpt.csv"
Try {
#Connect to PnP Online
Connect-PnPOnline -Url $AdminCenterURL -Interactive
#Get All Site Collections
$SiteCollections = Get-PnPTenantSite -IncludeOneDriveSites:$false
$RecyclebinData = @()
$Counter = 1
#Loop through each site collection
ForEach($Site in $SiteCollections)
{
Try {
Write-host "Processing Site ($Counter of $($SiteCollections.count):" $Site.URL -f Yellow
#Connect to the site
Connect-PnPOnline -Url $Site.URL -Interactive
#Get Recycle bin Item Sizes
$FirstStageSize = Get-PnPRecycleBinItem -RowLimit 500000 -FirstStage | Measure-Object -Property Size -Sum
$SecondStageSize = Get-PnPRecycleBinItem -RowLimit 500000 -SecondStage | Measure-Object -Property Size -Sum
$FirstStageSizeInMB = [Math]::Round($FirstStageSize.Sum/1MB,2)
$SecondStageSizeInMB = [Math]::Round($SecondStageSize.Sum/1MB,2)
$TotalSize = $FirstStageSizeInMB+$SecondStageSizeInMB
#Collect Data
$RecyclebinData+= [PSCustomObject][ordered]@{
SiteName = $Site.Title
URL = $Site.URL
FirstStageSize = $FirstStageSizeInMB
SecondStageSize = $SecondStageSizeInMB
TotalSize = $TotalSize
}
$Counter++
}
Catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
}
#Export the data to CSV
$RecyclebinData | Format-Table
$RecyclebinData | Export-CSV -Path $OutputPath -NoTypeInformation
}
Catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
