Skip to content

Instantly share code, notes, and snippets.

@vikaskumar185
Last active July 26, 2017 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vikaskumar185/45a52312a34092cbbdf0ee8559e48d72 to your computer and use it in GitHub Desktop.
Save vikaskumar185/45a52312a34092cbbdf0ee8559e48d72 to your computer and use it in GitHub Desktop.
This scripts helps deleting TargetTypes in SDL Web 8+ which has components already published. This script needs Powershell Core service module to run. Ex: in powershell, Run - .\DeleteTargetTypes.ps1 -TargetTypeTcmId 'tcm:0-17-65538'
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[string]$TargetTypeTcmId = 'tcm:0-17-65538', #Choose your own TargetType Id
[switch]$DryRun = $false
)
Begin{
try{
Write-Host "Preparing"
$modules = "Tridion-CoreService"
$modules | foreach {Import-Module $_ -ErrorAction Stop}
$client = Get-TridionCoreServiceClient
}
catch{
Write-Host ("Process stopped with error {0}"-f $_ ) -ForegroundColor Red -BackgroundColor Black
exit
}
}
Process{
try{
$publicationIds = (Get-TtmMapping).PublicationId
Write-Host ("Following will be updated:")
foreach ($publicationId in $publicationIds){
if ($DryRun){
Write-Host ("Would mark UnPublish for Publication {0} with Target Type ({1})" -f $publicationId, $TargetTypeTcmId)
}
else {
$client.RemovePublishStates($publicationId, $TargetTypeTcmId)
Write-Host ("Marked UnPublish for Publication {0} with Target Type ({1})" -f $publicationId, $TargetTypeTcmId)
}
}
Write-Host "Done"
}
catch{
Write-Host ("#Process stopped with error {0}"-f $_ ) -ForegroundColor Red -BackgroundColor Black
continue
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment