Skip to content

Instantly share code, notes, and snippets.

@dsolovay
Last active October 27, 2021 18:57
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 dsolovay/dfe50fbecf405fee781729e79b2bf4cf to your computer and use it in GitHub Desktop.
Save dsolovay/dfe50fbecf405fee781729e79b2bf4cf to your computer and use it in GitHub Desktop.
Get IDs from Sitecore 10.1 Upgrade scripts
Param(
# Input file
[Parameter()]
[String]
$InputFile,
[Parameter()]
[Switch]
$FormatForSql
)
$output = Get-Content $InputFile | % {[Regex]::match($_, "^.{36}(.{36})").Groups[1].Value}
if ($FormatForSql)
{
return ($output | ForEach-Object {"('$_')"}) -join ','
}
else {
return $output
}
# Not yet a script, but I ran these commands to find IDs that were not in Unicorn YAML files.
$unicornIds = gci -filter *.yml -recurse | % { (gc $_ | ConvertFrom-Yaml | select -ExpandProperty Id).ToUpper()}
$orphens = $masterids | ? {-not $unicornIds.Contains($_)}
create table #Ids (id uniqueidentifier)
Insert into #Ids values <ids,,>
delete from VersionedFields where itemid in (select id from #Ids)
delete from SharedFields where itemid in (select id from #Ids)
delete from UnversionedFields where itemid in (select id from #Ids)
delete from Items where id in (select id from #Ids)
@dsolovay
Copy link
Author

Some scripts I used on a recent upgrade to 10.1. The first extracts IDs that were not cleaned up by the UpgradeApp. The idea is you take the log file, find the rows for each database that contain skipped items, and use this script to get the IDs. Then FindOrphans can be used to compare this list against your source control items. Finally, the SQL command allows you to delete items that are safe for deletion (because they are on source control, or have been manually inspected).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment