3

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

8

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.

| improve this answer | |
  • 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 – SitecoreNoob Aug 7 '18 at 14:28
0

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"
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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