Summary
Removing the lock on an object in SCCM using PowerShell.
Issue
When using ConfigMgr you will at some point come across the following error:
This occurs when an object does not have its lock flag removed upon closing (managed by the Serialized Editing of Distributed Objects mechanism), this could occur because you have logged into ConfigMgr using multiple consoles or if the interface simply has crashed and the lock was not removed.
Resolution
You can wait 30 minutes for the lock to expire and you *should* have access to the object again.
Alternatively as in SCCM 2007 you could run a database expression to remove the lock from the object directly in the database.
- Log on to the SQL Server holding your SCCM database using Microsoft SQL Server Management Studio
- Run a New Query
– Right click your CM Database
– Click New Query
- Find the LockID for the object you are trying to delete by running the following query
SELECT * FROM SEDO_LockState WHERE LockStateID <> 0
This will display ID’s of all items locked, locate the relevant user and note the LOCKID
- Delete the lock using the following expression
DELETE FROM SEDO_LockState WHERE LockID = ‘<LockID from step 3>’
This however is not a supported practice.
The better way is to use a PowerShell commandlet included in PowerShell toolset
Unlock-CMObject
Implementation
Usage of the commandlet is very simple
Unlock-CMObject -InputObject $(Get-CMApplication -Name '<application name>')
In our example the
Unlock-CMObject -InputObject $(Get-CMApplication -Name 'Mozilla Firefox 30')
To get a full list of options, as with all Microsoft commandlets simply type
get-help Unlock-CMObject -Full
How do you associate the lockid with the problem item name, so I can use it in the powershell script? When running the sql query I never get the name of the offending item and sometimes the exact syntax isnt known.
LikeLike
Hi Travis,
It may be easier if you could explain what you are trying to achieve 🙂
The above queries in SQL will search all objects for a lock state and display them.
Though i would recommend you use powershell to target specific applications instead when you find a locked app.
Are you trying to run a cleanup script to locate all locked objects?
In which case you could simply pipe every object the unlock-CMObject commandlet:
Get-CMPackage | ForEach-Object{Unlock-CMObject -InputObject $_}
LikeLike