6

Is there a quick way to unlock all the items locked by a specific user from an admin account?

4 Answers 4

13

Something like that should do the trick:

Get-ChildItem master:\content -rec | 
  Where-Object { $_.Locking.GetOwner() -eq "sitecore\USERNAME" } | 
  % { $_.Locking.Unlock() }

You just take all the child items of the sitecore\content item, check if your chosen user is the owner of it and unlock the item.

1
  • the script seems to work fine , but the 'my items' list still shows the items are locked , i have tried clearing cache and cleaning up databases Commented Aug 7, 2018 at 14:28
4

This discussion is a bit old, but I think this is worth mentioning. If the "Reports" module is installed you can use the Reporting Tools -> PowerShell Reports -> Security Audit -> Locked Items report for this. It allows you to lookup the locked item of one or more specific users and unlock them all. It also comes with some filter, for example the root item and max dates a item is locked.

2

I ended up creating a slightly more verbose script that, when run in PowerShell ISE, allows you to select a specific location and user:

Parameter prompt

$root = Get-Item -Path "master:/sitecore/content"
$user = ""

$props = @{
    Parameters = @(
        @{ Name = "root"; Title="Choose the report root"; Tooltip="Only items from this root will be returned."; },
        @{ Name = "user"; Title="Locking User"; Editor="user" }
    )
    Title = "Unlock items"
    Width = 550
    Height = 300
    ShowHints = $true
    Icon = [regex]::Replace($PSScript.Appearance.Icon, "Office", "OfficeWhite", [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)
}

$result = Read-Variable @props

if($result -eq "cancel") {
    exit
}

$script:counter = 0
$script:unlockedCounter = 0

$owner = $user.Replace("\","\\")

function Unlock-Item-And-Descendants {
    param(
        [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
        [Sitecore.Data.Items.Item]$item
    )

    if ($item["__Lock"] -match $owner) {
        Write-Host "Unlocking" $item.Paths.ContentPath ":" $item.ID
        Unlock-Item $item #| Out-Null
        $script:unlockedCounter++
        if ($script:unlockedCounter % 500 -eq 0) {
            Write-Host "$script:unlockedCounter items unlocked"
        }
    }

    $script:counter++
    if ($script:counter % 500 -eq 0) {
        Write-Host "$script:counter items reviewed"
    }

    foreach ($childItem in $item.Children) {
        Unlock-Item-And-Descendants -Item $childItem
    }
}

Unlock-Item-And-Descendants -Item $root

Write-Host "Unlocked $script:unlockedCounter total items"
Write-Host "Reviewed $script:counter total items"
1

A small addition to (and thank you to) Mareks answer. The script only opened the English items for me (EN).

I've added -Language * and this did the trick for me.

Get-ChildItem master:\content -rec -Language * | 
  Where-Object { $_.Locking.GetOwner() -eq "sitecore\USERNAME" } | 
  % { $_.Locking.Unlock() }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.