Skip to content

Instantly share code, notes, and snippets.

@michaellwest
Last active June 10, 2018 10:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaellwest/d375c8814fdd850c275f3a834a1010f2 to your computer and use it in GitHub Desktop.
Save michaellwest/d375c8814fdd850c275f3a834a1010f2 to your computer and use it in GitHub Desktop.
Transfer lock ownership from one user to another using Sitecore PowerShell Extensions.
<#
.SYNOPSIS
Find all items locked by a specific user and transfer to another user.
.DESCRIPTION
This report helps identify all of the items locked by a user and transfers to another user.
.NOTES
Michael West
#>
$scriptItem = Get-Item -Path $SitecoreCommandPath
$icon = $scriptItem.Appearance.Icon -replace "16x16","32x32"
$settings = @{
Title = "Report Filter"
Width = "450"
Height = "250"
OkButtonName = "Proceed"
CancelButtonName = "Abort"
Description = "Filter items locked by a specific user."
Parameters = @(
@{ Name = "userLockOwner"; Title="Current User"; Editor="user"; Domain="sitecore"; },
@{ Name = "userNewLockOwner"; Title="New User"; Editor="user"; Domain="sitecore"; }
)
Icon = $icon
}
$result = Read-Variable @settings
if($result -ne "ok") {
Exit
}
$reportProperties = @{
Property = @("Name", "Id", "ItemPath", @{Label="Locked by"; Expression={$_.Locking.GetOwner() } })
Title = "Items with lock reassigned"
InfoTitle = "Items with lock reassigned"
InfoDescription = "Items with the lock set '$($userLockOwner)' have been transferred to $($userNewLockOwner)."
}
$items = Get-Item -Path "master:" -Query "/sitecore//*[@__lock!='' and @__lock!='<r />']"
$items | ForEach-Object {
$PSItem."__Lock" = $PSItem."__Lock".Replace("$userLockOwner","$userNewLockOwner")
$PSItem
} | Show-ListView @reportProperties
Close-Window
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment