High priority SCCM applications

This post is about getting all high priority SCCM applications using PowerShell. Today I had to check our server how many applications are set to High (Distribution Priority). The customer has a total of 40 distribution points (pull and push) all over the world and configured sophisticated BITS rules and schedules. Therefore, ConfigMgr only replicates high priority applications using higher bandwidth.

Screenshot of high priority in GUI

How to get the application properties

Now, to get information about SCCM applications, there’s a simple cmdlet available: “Get-CMApplication“. But the result is rather disappointing if you’re looking for advanced properties like “InstallCommandLine”, “DetectAction” or “Priority”.

ConfigMgr stores all those properties in an XML string “SDMPackageXML”.

Get-CMApplication -Name "UltraEdit 24.20.44"

Screenshot of SDMPackageXML string

We need to first deserialize this string and filter the results to match the xml tag “HighPriority”. Therefore assign a variable to the Get-CMApplication so that you can access the SDMPackageXML property and send the value to a text file.

$Prio = Get-CMApplication -Name "UltraEdit 24.20.44"
$Prio.SDMPackageXML | Out-File C:\temp\SDMPackageXML.txt

Open up the TXT file and copy-paste the contents to one of the XML beautifiers out there. As a result the XML code is much easier to read. Disassembling the structure is a piece of cake now.

Screenshot of SDMPackageXML string beautified

Type accelerators (like [version]) come in very handy. [xml] helps accessing a specific tag within any XML string. You can use the XML hierarchy like a method or a property on an object. Enclose the whole variable in parenthesis and put the [xml] in front. Then use the structure we just found out to grab the appropriate value, which results in HighPriority = 1 in this example.

([xml]$Prio.SDMPackageXML).AppMgmtDigest.Application.HighPriority

high priority sccm applications

The final script to find high priority sccm applications

The final script to find all high priority sccm applications and more looks like this:

Function Get-ITBApplicationDistributionPriority {
    <#
    .SYNOPSIS
        This script gets information about the priority of applications.
    .DESCRIPTION
        This script gets information about the priority of applications. Use this script on any machine having
        ConfigMgr Console installed. The result will be 3 different txt files for each priority type in the current
        directory. You could use those files later to set the priority to your liking. Omitting the parameters
        uses Site "CM1" and application "7-Zip*" as an example.
    .PARAMETER SiteCode
        Specify the SiteCode of your ConfigMgr Site.
    .PARAMETER Name
        Specify the name or part of the name of an application (wildcard *).
    .PARAMETER All
        Specify this parameter to query ALL applications. Parameter 'Name' will be ignored.
    .EXAMPLE
        Get-ITBApplicationDistributionPriority -SiteCode "CM3" -Name "Ultra*"
        Gets the priority of CM3 site applications using the name filter "ultra*".
    .EXAMPLE
        Get-ITBApplicationDistributionPriority -SiteCode "CM3" -All
        Gets the priority of ALL CM3 site applications.
    .LINK
        
High priority SCCM applications
.NOTES Author: Fabian Szalatnay Date: April 23, 2019 Ver. 1.0: Initial release Update 1.1: Added PowerShell header and documentation. Made it dynamic using parameters. #> param( [string]$SiteCode = "CM1", [string]$Name = "7-Zip*", [switch]$All ) # Import SCCM module Write-Output "Importing SCCM module..." # Import the ConfigurationManager.psd1 module Import-Module "$($ENV:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1" if ($All -eq $True) { # Cleanup first Remove-Item -Path ".\HighPriority_All.txt" -Force -ErrorAction SilentlyContinue Remove-Item -Path ".\LowPriority_All.txt" -Force -ErrorAction SilentlyContinue Remove-Item -Path ".\MediumPriority_All.txt" -Force -ErrorAction SilentlyContinue # Get all SCCM applications Write-Output "Getting all SCCM applications..." Push-Location "${SiteCode}:" Get-CMApplication | Sort-Object -Property LocalizedDisplayName | ForEach-Object { $AppFullName = $_.LocalizedDisplayName $Prio = ([xml]$_.SDMPackageXML).AppMgmtDigest.Application.HighPriority Switch($Prio) { 1 { Write-Output "$AppFullName is HighPriority." Pop-Location $AppFullName | Out-File -FilePath ".\HighPriority_All.txt" -Append } 3 { Write-Output "$AppFullName is LowPriority." Pop-Location $AppFullName | Out-File -FilePath ".\LowPriority_All.txt" -Append } default { Write-Output "$AppFullName is MediumPriority." Pop-Location $AppFullName | Out-File -FilePath ".\MediumPriority_All.txt" -Append } } } # Go to original location in case query returns no apps Pop-Location } else { # Cleanup first Remove-Item -Path ".\HighPriority_Single.txt" -Force -ErrorAction SilentlyContinue Remove-Item -Path ".\LowPriority_Single.txt" -Force -ErrorAction SilentlyContinue Remove-Item -Path ".\MediumPriority_Single.txt" -Force -ErrorAction SilentlyContinue # Get single SCCM application Write-Output "Getting SCCM application ""$Name""..." Push-Location "${SiteCode}:" Get-CMApplication -Name $Name | Sort-Object -Property LocalizedDisplayName | ForEach-Object { $AppFullName = $_.LocalizedDisplayName $Prio = ([xml]$_.SDMPackageXML).AppMgmtDigest.Application.HighPriority Switch($Prio) { 1 { Write-Output "$AppFullName is HighPriority." Pop-Location $AppFullName | Out-File -FilePath ".\HighPriority_Single.txt" -Append } 3 { Write-Output "$AppFullName is LowPriority." Pop-Location $AppFullName | Out-File -FilePath ".\LowPriority_Single.txt" -Append } default { Write-Output "$AppFullName is MediumPriority." Pop-Location $AppFullName | Out-File -FilePath ".\MediumPriority_Single.txt" -Append } } } # Go to original location in case query returns no apps Pop-Location } }

Save the code to a file called “Get-ITBApplicationDistributionPriority.ps1” and use dot sourcing to make the function available to your session. After that use the function like any other cmdlet.

Example:

. .\Get-ITBApplicationDistributionPriority.ps1
Get-ITBApplicationDistributionPriority -SiteCode "CM1" -Name "Ultra*"

This will create text files for each priority type containing the application names of all “Ultra*” apps on CM1. I chose text files because it’s simple and allows me to process them later easily.

Maybe I will blog part 2 on how to set all high priority apps to medium.

2 thoughts on “High priority SCCM applications”

    • Actually you should get a text file for each priority type.

      I think you missed the “dot sourcing” part. Read the article carefully.
      If you run the script, nothing happens because the script contains a function. You need to load that function first, then you can use it. Run 2 commands:

      1. Load the function:
      . .\Get-ITBApplicationDistributionPriority.ps1
      (note the two dots)

      2. Run the new command:
      Get-ITBApplicationDistributionPriority -SiteCode “CM1” -Name “Ultra*”
      (run from a writable folder on your C:\ drive)

      Reply

Leave a Comment