Last active
July 26, 2017 14:03
-
-
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'
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
[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