Sitecore Powershell script to unlock all locked items in Sitecore

Pranay
May 16, 2020  ยท  3346 views

This post provides Sitecore PowerShell script to unlock all items locked in Sitecore by content authors.

If you are looking for a way to unlock all the items which are locked in Sitecore then here is the solution. This PowerShell script goes through all the items under a root node and unlocks them if they are locked.

Is this not the script you are looking for? Then check the complete list of Sitecore Powershell scripts

Sitecore Powershell script to unlock all locked items

$sourcePath = "/sitecore/content/Site1/Home"
function RunScript
{
    $items = Get-ChildItem -Path $sourcePath -Recurse
    $rootItem = Get-Item -Path $sourcePath
    $items = $items + $rootItem

    foreach ($item in $items)
    {
        foreach ($version in $item.Versions.GetVersions($true))
        {
            if($version.Locking.IsLocked())
            {
                $version.Editing.BeginEdit();
                $version.Locking.Unlock();
                $version.Editing.EndEdit();
                Write-Host "Item un-locked:" $item.ID $version.Language;
            }
        }
    }
}

$items = RunScript

Unlock Items PowerShell

AUTHOR

Pranay

A Software Engineer by profession, a part time blogger and an enthusiast programmer. You can find more about me here.


Post a comment




Thank you! You are now subscribed.

Sign up for our newsletter

Subscribe to receive updates on our latest posts.

Thank you! You are now subscribed.