Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Find and delete fields where the language is empty using Sitecore PowerShell Extensions.
$sql = @"
SELECT DISTINCT i.* FROM [dbo].[Items] i
INNER JOIN [dbo].[VersionedFields] v
ON i.ID = v.ItemId
WHERE v.[Language] = ''
--SELECT COUNT(*) AS COUNT FROM [VersionedFields] WHERE [Language] = ''
--DELETE FROM [VersionedFields] WHERE [Language] = ''
Import-Function Invoke-SqlCommand
$db = Get-Database -Name "master"
$connection = [Sitecore.Configuration.Settings]::GetConnectionString($db.Name)
$builder = New-Object System.Data.SqlClient.SqlConnectionStringBuilder $connection
$dbName = $builder.InitialCatalog
$query = [string]::Format($sql, $dbName)
Invoke-SqlCommand -Connection $connection -Query $query | Select-Object -ExpandProperty ID | ForEach-Object { Get-Item -Path "master:" -ID ([ID]::Parse($_)) } | Show-ListView
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment