Búsqueda de sitios web

SharePoint Online: obtenga un informe de inventario de tipos de contenido mediante PowerShell


Requisito: SharePoint Online PowerShell para obtener el informe de tipos de contenido.

SharePoint Online: obtener tipos de contenido mediante PowerShell

Realizar un seguimiento de todos los tipos de contenido utilizados en su entorno de SharePoint Online puede resultar abrumador. PowerShell puede ayudarle a administrar y realizar un seguimiento de sus tipos de contenido de SharePoint Online al proporcionar un inventario de todos los tipos. Esta publicación de blog le mostrará cómo obtener un informe de todos los tipos de contenido en SharePoint Online usando PowerShell. Este informe puede resultar útil para documentar los tipos de contenido que se utilizan en su entorno.

Obtengamos todos los tipos de contenido de un sitio de SharePoint Online usando PowerShell 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"

#Config Parameters
$SiteURL="https://crescent.sharepoint.com"
$OutputFile ="C:\Temp\ContentTypes.csv"

Try {
    #Get Credentials to connect
    $Cred= Get-Credential

    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
 
    #sharepoint online powershell get all content types
    $ContentTypes = $Ctx.Web.ContentTypes
    $Ctx.Load($ContentTypes)
    $Ctx.ExecuteQuery()
 
    $ContentTypes | Select Name,Description,Id, Group
    #Export to CSV
    $ContentTypes | Select Name,Description,Id, Group | Export-CSV $OutputFile -notypeinformation -Delimiter "," -Append
}
Catch {
    write-host -f Red "Error Getting Content Types!" $_.Exception.Message
}

Este script genera un archivo CSV con todos los tipos de contenido del sitio determinado:

Generar informe HTML de inventario de tipos de contenido mediante PowerShell:

Generemos un informe HTML con todos los datos, campos y tipos de campos anteriores de cada tipo de contenido.


#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"

#Config Parameters
$SiteURL="https://crescent.sharepoint.com"
$ReportOutput ="C:\Temp\ContentTypes.htm"

#Define CSS Styles
$HeadTag = @"
<style type="text/css">
table {
 border-collapse: collapse; font-family: verdana,arial,sans-serif;
 font-size:11px; color:#333333; border-width: 1px; border-color: #a9c6c9;
 border: b1a0c7 0.5pt solid; border-spacing: 1px; border-collapse: separate; /*Sal Table format */  
}
 
th {
border-width: 1px; padding: 5px; background-color:#8064a2;
border: #b1a0c7 0.5pt solid; font-family: Calibri; height: 15pt; 
color: white;  font-size: 11pt;  font-weight: 700;  text-decoration: none;
}
 
td {
 border: #b1a0c7 0.5pt solid; font-family: Calibri; height: 15pt; color: black; 
 font-size: 11pt; font-weight: 400; text-decoration: none; 
 padding:5px;
}
 
tr:nth-child(even) { background-color: #e4dfec; }
</style>
"@
 
Try {
    #Get Credentials to connect
    $Cred= Get-Credential

    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
 
    #Get all content types from the web
    $ContentTypes = $Ctx.Web.ContentTypes
    $Ctx.Load($ContentTypes)
    $Ctx.ExecuteQuery()
 
    $BodyContent="<center><h3> SharePoint Online: Content Type Inventory Report </h3></center>"
    $BodyContent += $ContentTypes | Select Name,Description,Id, Group | ConvertTo-Html -Fragment

    ForEach($CType in $ContentTypes)
    {
        #Get Content type fields
        $Ctx.load($CType.Fields)
        $Ctx.ExecuteQuery()

        #Add the Data to Report
        $BodyContent += "<br/><th><b>Content Type Name: </b>$($CType.Name)</th>"
        $BodyContent += $CType.Fields | where { $_.Hidden -eq $false -and $_.Title -ne "Content Type" } | Select Title, @{Expression={$_.TypeDisplayName }; Label="Field Type"} | ConvertTo-Html -Fragment
    }
    ConvertTo-HTML -Title "Content Type Inventory Report" -Head $HeadTag -Body $BodyContent | Out-File $ReportOutput

    Write-host -f Green "Content Type Report Generated Successfully!" $_.Exception.Message
}
Catch {
    write-host -f Red "Error Generating Content Types Report!" $_.Exception.Message
}

Y el resultado de muestra del informe, que enumera todos los tipos de contenido y sus campos:

Artículos relacionados