In my Sitecore environment, there are 100+ non-admin users are working and we have been asked many times if it is possible for non admin users in Sitecore to be able to unlock items that have been locked by others Users. But in open, we dont have option for non-admin users to Un-Lock the others locked items, in this case they need to contact the specific person or admin users for Un-Locking items.

But this is a feature that many user want to perform Un-locking without others support, So based on requirement we thought to write custom command to unlock the items with help of Sitecore Powershell extension.

In this article, we going to see how to create custom Powershell script for Un-Locking the parent and child items for all the language versions.

STEP 1:

First you need to Get Source , child path items and assigned to the variables ($rootItem, $ChildItems ). After below script execution, the variable $items will contain the parent and its child items collection.

$sourcePath = “/sitecore/content/Sites/White/home/components”
$rootItem = Get-Item -Path $sourcePath
$ChildItems = Get-ChildItem -Path $sourcePath -Recurse
$items = $ChildItems + $rootItem

STEP 2:

Next you need to start looping the items ($items) one by one to check for all the languages.

foreach ($item in $items)
{
foreach ($version in $item.Versions.GetVersions($true))
{
Your unlocking login here….
}
}

STEP 3:

The main logic is to check each item with each language version to verify whether its locked or not. If its locked then below condition will allow to Un-Lock the specific item on specific language version.

if($version.Locking.IsLocked())
{
$version.Editing.BeginEdit();
$version.Locking.Unlock();
$version.Editing.EndEdit();
Write-Host “Item Un-locked” $item.ID “for Language” $version.Language;
}

Full code

OUTPUT: