SharePoint Online: PowerShell'i kullanarak İçerik Türü Envanter Raporu Alma
Gereksinim: İçerik türleri raporunu almak için SharePoint Online PowerShell.
SharePoint Online: PowerShell'i kullanarak İçerik Türlerini Alma
SharePoint Online ortamınızda kullanılan tüm içerik türlerini takip etmek göz korkutucu olabilir. PowerShell, her türden bir envanter sağlayarak SharePoint Online içerik türlerinizi yönetmenize ve takip etmenize yardımcı olabilir. Bu blog gönderisi, PowerShell kullanarak SharePoint Online'daki tüm içerik türlerinin raporunu nasıl alacağınızı gösterecektir. Bu rapor, ortamınızda kullanılan içerik türlerinin belgelenmesinde yararlı olabilir.
PowerShell kullanarak bir SharePoint Online sitesinin tüm içerik türlerini alalım ve bunları bir CSV dosyasına aktaralım:
#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
}
Bu komut dosyası, belirtilen sitedeki tüm içerik türlerini içeren bir CSV dosyası oluşturur:
PowerShell kullanarak İçerik Türleri Envanteri HTML Raporu Oluşturma:
Yukarıdaki tüm verileri, alanları ve her içerik türünün alan türlerini içeren bir HTML raporu oluşturalım.
#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
}
Raporun tüm içerik türlerini ve alanlarını listeleyen örnek çıktısı:

