Last active
July 23, 2017 10:27
-
-
Save BasantPandey/5fd69619a828431d17c53ffd1eb20d3b to your computer and use it in GitHub Desktop.
Remove-PnPContentType using CSV
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
ContentTypeName | ||
---|---|---|
MyContentType | ||
MyContentType2 | ||
MyContentType3 | ||
MyContentType4 | ||
MyContentType5 |
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
#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