Finding ConfigMgr Task Sequences with Invalid References

Last week, my coworker was in the process of cleaning up some old versions of our core applications and ran into an issue deleting an app. When she attempted to delete it, she got a message indicating that the application was used in a Task Sequence. Unfortunately, the dialog doesn’t offer any additional information as to WHICH Task Sequence is using the application. She asked me for help and here’s what we ended learning.

A Square Dozen Image

Disabled TS References

So the first thing we learned is that if you disable the Install Application step in a Task Sequence, the application reference gets removed from the Task Sequence References tab. This is good and bad. It’s good because it won’t prevent an application from being deleted. It’s bad because there’s no way to find out if it exists in any Task Sequences from the console.

A Square Dozen Image

Invalid Applications

We have around 75 Task Sequences currently. We keep archives of old ones plus we use several nested ones so they add up. I thought I could quickly find the reference manually so I started out manually clicking through each Task Sequence with the References tab selected so I could quickly skim through the references. Within a few minutes, I was done and was unable to find the reference. I thought that maybe the Application was disabled in the TS but based on the way Disabled works, we should have been able to delete. I ended up running some PowerShell commands (script below) and was able to find the Task Sequence where the application was referenced. When I opened the Task Sequence, I received an alert indicating that one of my application references was invalid. During the cleanup process, the deployment type had been deleted from the application. While you can’t delete an application if it’s referenced by a Task Sequence, you CAN delete it’s deployment types, which then breaks the reference apparently.

Missing deployment type breaks step.
Missing deployment type breaks step.

One or more of selected applications is not valid
One or more of selected applications is not valid

Scripting the Fix

If you launch the PowerShell console from the ConfigMgr console, you can run these commands to find out useful information about your Applications and their references.

Get Applications

This command will return the list of applications and their counts of places they are used. For Task Sequences, you would look for NumberOfDependentTS.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
Get-CMApplication | where-Object NumberOfDependentTS -gt 0 | select LocalizedDisplayName, Number*

#####################
#RESULTS#

LocalizedDisplayName        : Google Chrome
NumberOfDependentDTs        : 0
NumberOfDependentTS         : 1
NumberOfDeployments         : 2
NumberOfDeploymentTypes     : 1
NumberOfDevicesWithApp      : 0
NumberOfDevicesWithFailure  : 0
NumberOfSettings            : 0
NumberOfUsersWithApp        : 0
NumberOfUsersWithFailure    : 0
NumberOfUsersWithRequest    : 0
NumberOfVirtualEnvironments : 0

Get Task Sequences

This command will get all Task Sequences that have references to any Applications/Packages/Etc.

1
2
3
4
5
6
7
Get-CMTaskSequence | Where-Object References -ne $null | select Name, References

#####################
#RESULTS#
Name    References
----    ----------
Test TS {...

Get Applications that have Dependent Task Sequences

This command will return all applications that have Dependent Task Sequences but don’t have any Deployment Types. Note, you can change out Application for Package in any of these commands.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
Get-CMApplication | Where-Object {$_.NumberOfDependentTS -gt 0 -and $_.NumberOfDeploymentTypes -eq 0}

#####################
#RESULTS#

SmsProviderObjectPath              : SMS_Application.CI_ID=16777520
ApplicabilityCondition             :
CategoryInstance_UniqueIDs         : {}
CI_ID                              : 16777520
CI_UniqueID                        : ScopeId_89BCCE7B-CC4E-458F-A3F9-7E5BE4ADEF9E/Application_37ca86a3-9a6e-4bd2-aa41-d08c7692fef9/6
CIType_ID                          : 10
CIVersion                          : 6
ConfigurationFlags                 : 0
CreatedBy                          : ASD\Adam
DateCreated                        : 2/2/2019 9:44:06 PM
DateLastModified                   : 2/3/2019 12:15:54 AM
EffectiveDate                      :
EULAAccepted                       : 2
.......

Finding the Task Sequences that References the invalid applications.

Run this to find all Applications and Task Sequences that don’t have a deployment type and have an invalid reference.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
$Applications = Get-CMApplication | Where-Object {$_.NumberOfDependentTS -gt 0 -and $_.NumberOfDeploymentTypes -eq 0}
$TaskSequences = Get-CMTaskSequence | Where-Object { $_.References -ne $null }

# Run application report
foreach ($Application in $Applications) {
    foreach ($TaskSequence in $TaskSequences) {
        $Ref = New-Object PSObject
        $Ref | Add-Member -type NoteProperty -Name 'Application Name' -Value $Application.LocalizedDisplayName
        $Ref | Add-Member -type NoteProperty -Name 'Package ID' -Value $Application.PackageID
        $Ref | Add-Member -type NoteProperty -Name 'Task Sequence Name' -Value $TaskSequence.Name

    }
}

$Ref

#####################
#RESULTS#
Application Name   Package ID Task Sequence Name
----------------   ---------- ------------------
Google Chrome-copy            Test TS

Summary

From here, I just manually went into the Task Sequence and resolved the issue. I’m haven’t scripted Task Sequence stuff enough yet to feel comfortable just blindly removing the invalid reference. Hopefully this gets you through the hard part.

Well that’s all I’ve got for this one. Hopefully you find it useful. I’d like to thank Maurice Daly for his post on cleaning up applications. It saved me a few steps on putting everything together.