-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #673 from chandaniprajapati/devc-contentype-details
PnP script sample: export content type details to CSV
- Loading branch information
Showing
4 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
--- | ||
plugin: add-to-gallery | ||
--- | ||
|
||
# Export Content Type Details To CSV | ||
|
||
## Summary | ||
This example illustrates how to export all content types present on websites, capturing essential details like Name, ID, Scope, Schema, Fields, and additional information, then organizing them into a CSV format. | ||
|
||
# [PnP PowerShell](#tab/pnpps) | ||
|
||
```powershell | ||
$siteUrl = Read-Host "Enter site URL" | ||
$username = "[email protected]" | ||
$password = "********" | ||
$secureStringPwd = $password | ConvertTo-SecureString -AsPlainText -Force | ||
$creds = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $secureStringPwd | ||
$dateTime = "{0:MM_dd_yy}{0:HH_mm_ss}" -f (Get-Date) | ||
$basePath = "D:\Contributions\Scripts\Logs\" | ||
$csvPath = $basePath + "\ContentTypeData" + $dateTime + ".csv" | ||
$global:ctData = @() | ||
Function Login() { | ||
[cmdletbinding()] | ||
param([parameter(Mandatory = $true, ValueFromPipeline = $true)] $creds) | ||
Write-Host "Connecting to Site '$($siteUrl)'" -ForegroundColor Yellow | ||
Connect-PnPOnline -Url $siteUrl -Credentials $creds | ||
Write-Host "Connection Successful!" -ForegroundColor Green | ||
} | ||
Function ContentTypeDetails() { | ||
try { | ||
Write-Host "Getting content type details..." -ForegroundColor Yellow | ||
$allContentTypes = Get-PnPContentType | ||
Foreach ($contentType in $allContentTypes) | ||
{ | ||
#Collect Content Type Data | ||
$ctName = $contentType.Name | ||
$ctId = $contentType.Id | ||
$ctGroup = $contentType.Group | ||
$ctDescription = $contentType.Description | ||
$ctPath = $contentType.Path | ||
$ctScope = $contentType.Scope | ||
$ctStringId = $contentType.StringId | ||
$ctSchemaXml = $contentType.SchemaXml | ||
$contentTypeFields = Get-PnPProperty -ClientObject $contentType -Property Fields | ||
$contentTypeFieldsCount = $contentTypeFields.Count | ||
$contentTypeFieldsSchema = $contentTypeFields.SchemaXml | ||
$contentTypeTitle = ($contentTypeFields | select-object -property Title | foreach-object { $_.Title }) -join ',' | ||
$global:ctData += [PSCustomObject] @{ | ||
Name = $ctName | ||
ID = $ctId | ||
Group = $ctGroup | ||
Description = $ctDescription | ||
Path = $ctPath | ||
Scope = $ctScope | ||
StringId = $ctStringId | ||
SchemaXml = $ctSchemaXml | ||
Fields = $contentTypeTitle | ||
FieldCount = $contentTypeFieldsCount | ||
FieldSchemaXMl = $contentTypeFields.SchemaXml | ||
} | ||
} | ||
Write-Host "Getting content type details successfully!..." -ForegroundColor Green | ||
} | ||
catch { | ||
Write-Host "Error in getting content type information:" $_.Exception.Message -ForegroundColor Red | ||
} | ||
Write-Host "Exporting to CSV..." -ForegroundColor Yellow | ||
$global:ctData | Export-Csv $csvPath -NoTypeInformation -Append | ||
Write-Host "Exported to CSV successfully!..." -ForegroundColor Gree | ||
} | ||
Function StartProcessing { | ||
Login($creds); | ||
ContentTypeDetails | ||
} | ||
StartProcessing | ||
``` | ||
[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)] | ||
|
||
*** | ||
## Contributors | ||
|
||
| Author(s) | | ||
|-----------| | ||
| Chandani Prajapati (https://github.com/chandaniprajapati) | | ||
|
||
|
||
[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)] | ||
<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/spo-export-content-type-details-to-csv" aria-hidden="true" /> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions
57
scripts/spo-export-content-type-details-to-csv/assets/sample.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
[ | ||
{ | ||
"name": "spo-export-content-type-details-to-csv", | ||
"source": "pnp", | ||
"title": "Export Content Type Details To CSV", | ||
"shortDescription": "This script exports all content types available on sites to CSV.", | ||
"url": "https://pnp.github.io/script-samples/spo-export-content-type-details-to-csv/README.html", | ||
"longDescription": [ | ||
"This script exports all content types available on sites, including basic information such as Name, ID, Scope, Schema, Fields, and more, into a CSV format." | ||
], | ||
"creationDateTime": "2024-03-05", | ||
"updateDateTime": "2024-03-05", | ||
"products": [ | ||
"SharePoint" | ||
], | ||
"metadata": [ | ||
{ | ||
"key": "PNP-POWERSHELL", | ||
"value": "2.3.0" | ||
} | ||
], | ||
"categories": [ | ||
"Report", | ||
"Data" | ||
], | ||
"tags": [ | ||
"SharePoint Online", | ||
"Connect-PnPOnline", | ||
"Get-PnPContentType", | ||
"Get-PnPProperty", | ||
"Export-Csv" | ||
], | ||
"thumbnails": [ | ||
{ | ||
"type": "image", | ||
"order": 100, | ||
"url": "https://raw.githubusercontent.com/pnp/script-samples/main/scripts/spo-export-content-type-details-to-csv/assets/preview.png", | ||
"alt": "Preview of the sample <title>" | ||
} | ||
], | ||
"authors": [ | ||
{ | ||
"gitHubAccount": "chandaniprajapati", | ||
"company": "Rapid Circle", | ||
"pictureUrl": "https://avatars.githubusercontent.com/u/52065929?v=4", | ||
"name": "Chandani Prajapati" | ||
} | ||
], | ||
"references": [ | ||
{ | ||
"name": "Want to learn more about PnP PowerShell and the cmdlets", | ||
"description": "Check out the PnP PowerShell site to get started and for the reference to the cmdlets.", | ||
"url": "https://aka.ms/pnp/powershell" | ||
} | ||
] | ||
} | ||
] |