Deleting Applications from Orphaned Task Sequences in SCCM

Deleting Applications from Orphaned Task Sequences in SCCM

Have you ever tried to delete or retire an application but cannot because it is either referenced to other deployments or task sequences? And the dependent task sequence is blank?

For dependent apps you can go to the app’s properties and see the app relationships (take note of the revision # and delete that one):

To remove the task sequence reference, click on the Task Sequences tab for the app and see which ones it references.

But what if you have dependent task sequences and the task sequence was deleted long ago? Now you have an orphaned object reference in the SCCM database.

Solution:

***Use at your own risk***

Example: I could not delete the application “FireFox ESR 60.6.3” in the CM console.

  • Cannot retire or delete the application because it references a task sequence(s) that no longer exists.
  • Searched and made sure that there is no reference task sequence. 

Follow the below troubleshooting steps:

Step 1 : On the SQL server run the below query to get the Application Unique ID. 

SELECT APP.CI_ID [App CI ID], APP.CI_UniqueID [App Unique ID], APP.DisplayName [App Name],
DT.CI_UniqueID [DT Unique ID], DT.ContentId [DT Content ID],
CIA.Assignment_UniqueID [Assignment ID], CIA.CollectionID, CIA.CollectionName,
CASE CIA.OfferTypeID WHEN 0 THEN ‘Required’ WHEN 2 THEN ‘Available’ WHEN 3 THEN ‘Simulate’ ELSE ‘Unknown’ END AS [Deployment Purpose],
CASE C.CollectionType WHEN 1 THEN ‘User Collection’ WHEN 2 THEN ‘Device Collection’ ELSE ‘Unknown’ END AS [Collection Type],
DT.Technology, DT.DisplayName [DT Name]
FROM fn_ListApplicationCIs(1033) APP
JOIN fn_ListDeploymentTypeCIs(1033) DT ON DT.AppModelName = APP.ModelName AND DT.IsLatest = 1
LEFT JOIN v_CIAssignmentToCI CIACI ON CIACI.CI_ID = APP.CI_ID
LEFT JOIN v_CIAssignment CIA ON CIACI.AssignmentID = CIA.AssignmentID
LEFT JOIN v_Collection C ON C.CollectionID = CIA.CollectionID
WHERE APP.IsLatest = 1 AND APP.DisplayName = ‘Application Name’ — Replace with your Application Name as it appears in SCCM.

Alternatively, the below query can be run in PowerShell as an admin to get the App CI unique ID 

(get-cmapplication -Name ‘Application Name’ -fast).ModelName

Returns:

Step 2 : Get the TS_ID it is linked to:

select TS_ID from TS_AppReferences

where AppModelName = ‘AppUniqueID’

*** You will see a /#, remove it or the query will fail. For example, run this:

This will return all the task sequences it is in:

Step 3 : Check if this TS is orphaned. The below query shouldn’t return anything. If it does, it means the TS isn’t orphaned (exists).


select PackageID [TS PackageID], Name from v_TaskSequencePackage where TS_ID in (
select TS_ID from TS_AppReferences where AppModelName = ‘<CIUniqueID>’)

Also, you can verify with the below query if task sequence is present in the database or not. 

select TS_ID, AppModelName from TS_AppReferences 

Step 4 :  Run a backup of the DB, then remove the orphaned TS reference

delete from TS_TaskSequence where TS_ID = <output from step 2>

  • Following the above steps, you should now be able to go back to SCCM and delete the application

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.