SharePoint Online: obtenga el tamaño del subsitio usando PowerShell
Requisito: Obtener el tamaño del subsitio en SharePoint Online.
¿Cómo obtener el tamaño del subsitio en SharePoint Online?
¿Está buscando una manera de obtener el tamaño de sus subsitios en SharePoint Online? Bueno, hay algunos enfoques que puede adoptar y los analizaremos cada uno para obtener el tamaño de cualquier subsitio en SharePoint Online. En esta publicación, le mostraré cómo obtener información sobre el tamaño de un subsitio en SharePoint Online desde la interfaz de usuario web. Además, compartiré el script para encontrar el tamaño del subsitio en SharePoint Online usando PowerShell.
Para conocer la cuota de almacenamiento que ocupa un subsitio en SharePoint Online, vaya a:
- Navegue a su subsitio de SharePoint Online >> Haga clic en el engranaje de Configuración >> Información del sitio >> Ver todas las configuraciones del sitio.
En la página Configuración del sitio, haga clic en el enlace "Métricas de almacenamiento" en "Administración de la colección de sitios".
Esta página le proporciona el tamaño de cada subsitio del sitio en particular.
Obtener el tamaño del subsitio en SharePoint Online usando PowerShell
Como administrador de SharePoint Online, puede usar PowerShell para obtener el tamaño de una colección de sitios o un subsitio. Esto puede resultar útil al intentar identificar qué colecciones de sitios o subsitios utilizan más espacio de almacenamiento. Aquí está el PowerShell para obtener el tamaño del subsitio en SharePoint Online:
#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"
#Function to Get the size of a Folder in SharePoint Online
Function Get-SPOFolderSize([Microsoft.SharePoint.Client.Folder]$Folder)
{
Try
{
Write-host -f Yellow "Size of the Folder '$($Folder.ServerRelativeUrl)' : " -NoNewline
$FolderSize = 0
#Get all Files and Subfolders from the folder
$Ctx.Load($Folder.Files)
$Ctx.Load($Folder.Folders)
$Ctx.ExecuteQuery()
ForEach($File in $Folder.Files)
{
#Get File Size
$FolderSize += $File.Length
}
Write-host $FolderSize
#Process all Sub Folders
ForEach($Folder in $Folder.Folders)
{
#Call the function recursively
$FolderSize +=Get-SPOFolderSize $Folder
}
Return $FolderSize
}
Catch [System.Exception]
{
Write-Host -f Red "Error:"$_.Exception.Message
}
}
#parameters
$SiteURL = "https://Crescent.sharepoint.com/unitedstates"
#Get credentials to connect to SharePoint Online Admin Center
$Cred = Get-Credential
#Set up the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Get the Web
$Web = $Ctx.Web
$RootFolder = $Web.RootFolder
$Ctx.Load($RootFolder)
$Ctx.ExecuteQuery()
#Call the function to get Subsite size
$SubSiteSize = Get-SPOFolderSize -Folder $RootFolder
#sharepoint online powershell site size
Write-host "Toal Size of the subsite (MB): " -NoNewline
[Math]::Round($SubSiteSize/1MB, 2)
Este script de PowerShell obtiene el tamaño de un subsitio determinado. ¿Qué tal recuperar el consumo de almacenamiento de todos los subsitios en una colección de sitios?
PowerShell para encontrar el tamaño de todos los subsitios en una colección de sitios de SharePoint Online
Obtengamos el tamaño de todos los subsitios en una colección de sitios y exportémoslos a un archivo CSV.
#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"
#Function to Get the size of a Folder in SharePoint Online
Function Get-SPOFolderSize([Microsoft.SharePoint.Client.Folder]$Folder)
{
Try
{
Write-host -f Cyan "`t Size of the Folder '$($Folder.ServerRelativeUrl)' : " -NoNewline
$FolderSize = 0
#Get all Files and Subfolders from the folder
$Ctx.Load($Folder.Files)
$Ctx.Load($Folder.Folders)
$Ctx.ExecuteQuery()
ForEach($File in $Folder.Files)
{
#Get File Size
$FolderSize += $File.Length
}
Write-host $FolderSize
#Process all Sub Folders
Foreach($Folder in $Folder.Folders)
{
#Call the function recursively
$FolderSize +=Get-SPOFolderSize $Folder
}
Return $FolderSize
}
Catch [System.Exception]
{
Write-Host -f Red "Error:"$_.Exception.Message
}
}
Function Get-SPOSubsiteSize([Microsoft.SharePoint.Client.Web]$Web)
{
Write-host -f Yellow "Finding the Size of the subsite:"$web.Url
$StorageMetrics= @()
#Get the Root Folder of the Web
$Ctx = $Web.Context
$RootFolder = $Web.RootFolder
$Ctx.Load($RootFolder)
$Ctx.Load($Web.Webs)
$Ctx.ExecuteQuery()
#Call the function to get Subsite size
$SubSiteSize = Get-SPOFolderSize -Folder $RootFolder
$SizeinMB = [Math]::Round($SubSiteSize/1MB, 2)
Write-host -f Green "Toal Size of the subsite (MB): $SizeinMB `n"
#Add the result to an Array
$StorageData = New-Object PSObject
$StorageData | Add-Member NoteProperty SiteURL($web.Url)
$StorageData | Add-Member NoteProperty Size-MB([math]::Round($SubSiteSize/1MB,2))
$StorageMetrics += $StorageData
#Process all subsites
ForEach($Subweb in $web.Webs)
{
$StorageMetrics+=Get-SPOSubsiteSize $Subweb
}
Return $StorageMetrics
}
#parameters
$SiteURL = "https://Crescent.sharepoint.com"
$CSVPath="C:\Temp\SubsiteStorage.csv"
#Delete the Output Report, if exists
If (Test-Path $CSVPath) { Remove-Item $CSVPath }
#Get credentials to connect to SharePoint Online Admin Center
$Cred = Get-Credential
#Set up the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Get the Root Web
$Web = $Ctx.Web
$Ctx.Load($Web)
$Ctx.ExecuteQuery()
#Call the function to get subsite storage metrics
$SubsiteStorageMetrics = Get-SPOSubsiteSize $Web
#Export the results to CSV
$SubsiteStorageMetrics | Export-CSV -LiteralPath $CSVPath -NoTypeInformation
Este script devolverá una lista de subsitios y la cantidad de almacenamiento que se está utilizando actualmente. Si desea obtener el tamaño de la colección de sitios en SharePoint Online usando PowerShell, use: Verificar el tamaño de almacenamiento de la colección de sitios de SharePoint Online usando PowerShell
