Create a Package Containing Overridden Items

Created: 29 Sep 2023, last update: 4 Apr 2024

Create a Package Containing Overridden IAR Items

When working with Sitecore's IAR (Items as Resources), you may need to recover the original item from overridden or overwritten resource items. This can be easily accomplished using the Find-overwritten-Sitecore-resource-items tool. If you wish to view the differences between items, you can also perform a comparison using the same tool.

However, it's advisable to create a backup before proceeding with the restoration process. You can achieve this by making a Sitecore package of the items. Another use case can be for restoring on another environment. Below, you'll find a Sitecore PowerShell script for generating a package containing all overridden items.

Sitecore PowerShell script for Sitecore XM cloud or Sitecore 10.3+ Create a Sitecore Package With All overridden items as resource.

$item = Get-Item -Path master: -Query "/sitecore/system/"
$overriddenitems = $item.Database.DataManager.DataSource.GetOverriddenItems()

$package = New-Package "IAR-Overridden-items"

# Set package metadata
$currentuser = Get-User -Current
$package.Metadata.Author = $currentuser.Name
$package.Metadata.Publisher = "stockpick powershell script"
$package.Metadata.Version = "1.0"

# Add itemsto the package
ForEach ($itemguid in $overriddenitems)
    $Source = Get-Item -Path "master:" -ID $itemguid  | New-ExplicitItemSource -Name "Overridden items"

# Save package
Export-Package -Project $package -Path "$($package.Name)-$($package.Metadata.Version).zip" -Zip

# Offer the user to download the package
Download-File "$SitecorePackageFolder\$($package.Name)-$($package.Metadata.Version).zip"

Related Items as resources blogs
Items as resources by Sitecore part 3: restoring
Items as resources by Sitecore part 4: compare
Items as resources by Sitecore part 5: Gutter
Items as resources PowerShell Content Editor Warning

See also Github for a compleet tool in Sitecore PowerShell for managing Sitecore Items as resources including compair delete and creating package of selected items. Find-overwritten-Sitecore-resource-items


The Find-overwritten-Sitecore-resource-items tools has the option to select a specific resource file, and a option to manual select the items you want to package instead of package all overridden resource items from all packages.