Skip to content

Instantly share code, notes, and snippets.

@BasantPandey
Last active July 23, 2017 10:27
Show Gist options
  • Save BasantPandey/5fd69619a828431d17c53ffd1eb20d3b to your computer and use it in GitHub Desktop.
Save BasantPandey/5fd69619a828431d17c53ffd1eb20d3b to your computer and use it in GitHub Desktop.
Remove-PnPContentType using CSV
ContentTypeName
MyContentType
MyContentType2
MyContentType3
MyContentType4
MyContentType5
#Dev Import
Import-Module 'C:\Users\basantp\Documents\PNP Blog Section\Code\SharePointPnPPowerShell2013\SharePointPnP.PowerShell.2013.Commands.dll';
function Create-ContentType ($csvPath , $siteUrl) {
#connect to the root site collection first
Connect-PnPOnline –Url $siteUrl -CurrentCredentials
$message = "Connected to site : $siteUrl"
Write-Host $message
Write-Host $message -ForegroundColor Green
$MyFile = Import-Csv $csvPath
# Looping the csv file collection
foreach ($myRow in $MyFile) {
$ContentTypeName = $myRow.ContentTypeName
$ctype = Get-PnPContentType -Identity $ContentTypeName
if (!$ctype) {
try {
Remove-PnPContentType -Identity $ContentTypeName -Force
$message = "Content type : $ContentTypeName Deleted !!"
Write-Host $message
Write-Host $message -ForegroundColor green
}
catch {
$message = "Unable to delete Content type : $ContentTypeName !!"
Write-Host $message
Write-Host $message -ForegroundColor Red
Write-Host "$($_.Exception.Message)"
}
}
else {
$message = "Content type : $ContentTypeName !!, not found"
Write-Host $message
Write-Host $message -ForegroundColor Red
}
}
}
$siteUrl = "http://myintranet.com/sites"
$path = 'C:\Users\basantp\Documents\PNP Blog Section\Code\ContentType'
$inputFile = $path + "\RemoveContentType.csv"
Remove-ContentType $inputFile $siteUrl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment