Modifying Sitecore Locks from an old domain resolved using Sitecore Rocks Query Analyzer

I recently ran into a minor problem with locks within Sitecore. We had moved all of our users from an old domain to a new domain. This was fairly seamless except for the fact that the old domain users still had files locked within Sitecore. Yes, as an admin I could've manually removed the locks and checked in all files. However, I didn't feel like wasting the time to do it manually when I was sure I could write a script to do exactly what I needed. So I dove into Sitecore Rocks to see what I could do to solve the problem.

First thing I wanted to know was how many of these older domains had locks on items. So I ran the following query within Sitecore Rocks Query Analyzer:

select count() from /sitecore//*[contains(@__Lock,'olddomain')]
select @@name, @@Path, @__Lock from /sitecore//*[contains(@__Lock,'olddomain')]   if you prefer a listing of item information. 

After determining it was over the threshold for a manual update, I looked for a query solution to my problem. If I wanted to simply remove the lock, I could have execute a basic update query such as:

update set @__Lock="<r />" from /sitecore//*[contains(@__Lock,'olddomain')]

However, I wasn't 100% certain that these files were intended/ready to be checked in. Unlocking could've caused an unwanted change to be published (potentially). So the final query that I ended up using was:

replace "olddomain" with "newdomain" in @__Lock from /sitecore//*[contains(@__Lock,'olddomain')]

This was ideal as the locks were simply transferred to the same account on the new domain.


  1. Very cool. I enjoyed trying to create an alternative in Sitecore PowerShell Extensions. Check this out.

    Get-Item . -Query "/sitecore//*[contains(@__Lock,'olddomain')]" | ForEach-Object {
    $_ | Set-ItemProperty -Name __Lock -Value ($_.__Lock -replace "olddomain", "newdomain")

    1. Very cool! I'm just getting into PowerShell. Just joined a PowerShell User Group in hopes of increasing my knowledge. Very cool to see alternative ways of doing things.

    2. Hey Scott, you may find this very helpful in getting started with PowerShell...and Sitecore PowerShell.


Post a Comment