PowerShell: How to unlock objects in SCCM

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:

PowerShell_UnlockCMObject_Error_27032015

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.

  1. Log on to the SQL Server holding your SCCM database using Microsoft SQL Server Management Studio
  2. Run a New Query
    – Right click your CM Database
    – Click New Query
    PowerShell_UnlockCMObject_NewQuery_27032015
  3. 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
    PowerShell_UnlockCMObject_Search_27032015

  4. Delete the lock using the following expression
    DELETE FROM SEDO_LockState WHERE LockID = ‘<LockID from step 3>’

    PowerShell_UnlockCMObject_Delete_27032015

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')

PowerShell_UnlockCMObject_PowerShellUnlock_27032015

To get a full list of options, as with all Microsoft commandlets simply type

get-help Unlock-CMObject -Full
Advertisements

3 responses to “PowerShell: How to unlock objects in SCCM

  1. Pingback: ConfigMgr object locked for editing | Annoying stuff I figured out (or am trying to)·

  2. 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.

    Like

    • 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 $_}

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s