Encuentre todos los elementos web en uso en un sitio de SharePoint usando PowerShell
Requisito: Generar un informe para obtener el inventario de todos los elementos web en uso, en una colección de sitios de SharePoint.
Script de PowerShell para generar elementos web en uso en una colección de sitios:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Configuration parameters
$SiteURL = "https://intranet.crescent.com"
$ReportOutput="C:\Webparts-in-use.csv"
$ResultCollection = @()
#Get All Subsites in a site collection and iterate through each
$Site = Get-SPSite $SiteURL
ForEach($Web in $Site.AllWebs)
{
write-host Processing $Web.URL
# If the Current Web is Publishing Web
if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($Web))
{
#Get the Publishing Web
$PubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($Web)
#Get the Pages Library
$PagesLib = $PubWeb.PagesList
}
else
{
$PagesLib = $Web.Lists["Site Pages"]
}
#Iterate through all Pages
foreach ($Page in $PagesLib.Items | Where-Object {$_.Name -match ".aspx"})
{
$PageURL=$web.site.Url+"/"+$Page.File.URL
$WebPartManager = $Page.File.GetLimitedWebPartManager([System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
#Get All Web Parts data
foreach ($WebPart in $WebPartManager.WebParts)
{
$Result = New-Object PSObject
$Result | Add-Member -type NoteProperty -name "Site URL" -value $web.Url
$Result | Add-Member -type NoteProperty -name "Page URL" -value $PageURL
$Result | Add-Member -type NoteProperty -name "Web Part Title" -value $WebPart.Title
$Result | Add-Member -type NoteProperty -name "Web Part Type" -value $WebPart.GetType().ToString()
$ResultCollection += $Result
}
}
}
#Export results to CSV
$ResultCollection | Export-csv $ReportOutput -notypeinformation
Este script obtiene todos los elementos web de una colección de sitios y genera un informe en formato CSV.
¿Cómo encontrar el uso de un elemento web específico?
Supongamos que desea encontrar todos los elementos web de Bamboo en su entorno de SharePoint. Simple, simplemente cambie la Línea#34 a:
ForEach ($WebPart in $WebPartManager.WebParts | Where-Object { $_.GetType().ToString() -like "*bamboo*"} )
Buscar el uso de elementos web a nivel de aplicación web:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Configuration parameters
$WebAppURL = "https://intranet.crescent.com"
$ReportOutput="C:\Webparts-in-use.csv"
$ResultCollection = @()
#Get All Site Collections in the web application
$Sites = Get-SPWebApplication $WebAppURL | Get-SPSite
#Iterate through each Site collection
ForEach($Site in $Sites)
{
ForEach($Web in $Site.AllWebs)
{
write-host Processing $Web.URL
# If the Current Web is Publishing Web
if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($Web))
{
#Get the Publishing Web
$PubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($Web)
#Get the Pages Library
$PagesLib = $PubWeb.PagesList
}
else
{
$PagesLib = $Web.Lists["Site Pages"]
}
#Iterate through all Pages
foreach ($Page in $PagesLib.Items | Where-Object {$_.Name -match ".aspx"})
{
$PageURL=$web.site.Url+"/"+$Page.File.URL
$WebPartManager = $Page.File.GetLimitedWebPartManager([System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
#Get All Web Parts data
foreach ($WebPart in $WebPartManager.WebParts)
{
$Result = New-Object PSObject
$Result | Add-Member -type NoteProperty -name "Site URL" -value $web.Url
$Result | Add-Member -type NoteProperty -name "Page URL" -value $PageURL
$Result | Add-Member -type NoteProperty -name "Web Part Title" -value $WebPart.Title
$Result | Add-Member -type NoteProperty -name "Web Part Type" -value $WebPart.GetType().ToString()
$ResultCollection += $Result
}
}
}
#Export results to CSV
$ResultCollection | Export-csv $ReportOutput -notypeinformation -append
}
