2

Writing a script to allow editors to unlock an item locked by another user I used

New-UsingBlock(New-Object -TypeName "Sitecore.SecurityModel.SecurityDisabler"){
$item | Unlock-Item
}

This didn't raise errors, but didn't unlock the item

Directly calling the Unlock() method did work though

New-UsingBlock(New-Object -TypeName "Sitecore.SecurityModel.SecurityDisabler"){
    $item.Locking.Unlock()
    }

Is there a reason for this?

Note: this is only the briefest of outline, other possible differences include retrieving the item to unlock inside or outside the security disabler block, and getting multiple items (using a foreach-object for unlocking by second method, piping the results of the query using the first).

2
  • Two things to try. Add -PassThru to unlock command, if data is returned then it's not exiting on the security check. Second, try user switcher. Commented Mar 16, 2018 at 11:23
  • I'll try with -PassThru, but the second version of the code is working fine, so I'm mainly just curious. Commented Mar 16, 2018 at 11:26

0

Your Answer

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

Browse other questions tagged or ask your own question.