Package Software While You Sleep Using the SCCM Application Packager Script – Part 2

, , , , , , , , ,

Welcome to Part 2 of the 2-part series about the SCCM Application Packager Script! If you have not yet read Part 1, I highly recommend doing so before continuing.

The SCCM Packager Tool works by parsing and processing XML files known as “recipes”. Recipes provide the instructions to the SCCM Application Packager Script that allow it to create applications in SCCM. Recipes are broken down into 5 main nodes. This post will cover each of the nodes, many of the tags and properties found in each node, and their purpose. Once a general understanding of the recipes and their properties are established, we will dissect the 7-Zip recipe for further insights. Please note that there are more properties available than the ones explained here. All available properties and options are documented in the Template.xml file located in the “Recipes” folder of the SCCM Application Packager Script.

Application Node

The Application Node contains information for the application that will be visible to the end user when the it is deployed. Essentially, the Application Node defines what will be seen in Software Center for each application. The Application Node does not have many options overall, so they are all broken down below:

  • Name – The name of the application as shown in SCCM and the Software Center
  • Description – The description of the application in Software Center. Also sets the “Administrative Comments”
  • Publisher – The application publisher as shown in Software Center
  • AutoInstall – Whether to allow the application to install during a task sequence or not
  • UserDocumentation – Link for the application to provide the end user with more information
  • Icon – The filename of the application icon in the icon repository folder

Downloads Node

The Downloads Node is responsible for downloading and copying the application installers and any associated files to the application share. Multiple downloads can be specified (for things like 32 and 64-bit downloads), and each download should be named to correspond with a “DeploymentType” in the Deployment Types Node. Different destinations can also be specified for each download (see the Template.xml file for more information). The Downloads Node also has just a few options, the most common are as follows:

  • PrefetchScript – The prefetch script can be used to download the software or find the URL of the download for the application if a direct link to the application download isn’t available.
  • URL – The link to download the latest version of the application.
  • DownloadFileName – Specify the name of the file when it is downloaded
  • Version and FullVersion – These can be blank, but MUST be present in each download definition
  • DownloadVersionCheck – This can be used to check the version of the application that was downloaded. If the version can’t be checked directly, additional processing can be done here as well
  • AppRepoFolder – Allows different folders to be specified on the application share per download
  • ExtraCopyFunctions – If additional files like configurations, installation scripts, or “.mst” files are needed, they can be copied to the content share here

Deployment Types Node

The Deployment Types Node is where all the magic really happens. In the Deployment Types Node, multiple deployment types can be specified for a single application. At this time, Script and MSI deployment types are supported. Each deployment type supports things like: Custom installation and uninstall commands, Custom and multiple detection methods including script detection methods, Installation behavior, and dependencies. The number of options available are too great to list for the deployment types, so it is recommended to check out the Template.xml to see the options available.

Distribution Node

The Distribution Node is responsible for distributing the content to SCCM distribution points. Generally, only one option will need to be specified here, and that is whether or not to distribute the content. If the “DistributeContent” property is set to “True”, the content for the application will automatically be distributed to the distribution point group specified in SCCMPackager.prefs. The following options are also available in the Distribution Node:

  • DistributeContent – Set to True to distribute content, Set to false to skip distributing content
  • DistributeToGroup – Distribution Point group to distribute content to
  • DistributeToDPs – Distribution Point to distribute content to

Deployment Node

The Deployment Node is similar to the Distribution Node. It has very few options and, generally, the only option that needs to be set is “DeploySoftware”. If the “DeploySoftware” property is set to “True”, the software will automatically be deployed as available to the default collection specified in SCCMPackager.prefs. Additionally, a collection other than the default can be specified for deployment. Other options available in the Deployment Node are as follows:

  • DeploySoftware – Set to True to deploy the software, Set to false to skip deploying software
  • DeploymentCollection – Specify the name of a collection to deploy to other than the default


Recipe Breakdown – 7-Zip.xml

Now that we have a general idea of the purpose of recipes and the features available to them, let’s break down a simple one to demonstrate a real life example. The recipe for 7-Zip is relatively simple, containing two downloads and two MSI deployment types. One of these deployment types also contains a requirements rule. Below, each node of the 7-Zip recipe will be dissected and discussed.

7-Zip Application Node

    <Description>7-Zip is a file archiver with a high compression ratio. Free and Open Source Software</Description>
    <Publisher>Igor Pavlov</Publisher>

As described earlier, the Application Node is fairly simple overall. The 7-Zip application will be packaged with the name “7-Zip <Version>”, the Description as shown in Software Center will be: “7-Zip is a file archiver with a high compression ratio. Free and Open Source Software”. The Publisher and Link provided in Software Center will be “Igor Pavlov” and “” respectively. The SCCM Application Packager Script will also mark the option to allow the packaged application to be installed during a Task Sequence, and will choose the icon file “7Zip.ico” from the icon repository specified in SCCMPackager.prefs.

7-Zip Downloads Node

    <Download DeploymentType="DeploymentType1">
        <PrefetchScript>$URL = "$((Invoke-WebRequest |Select -ExpandProperty Links |where -Property href -like "*-x64.msi")[0].href)"</PrefetchScript>
        <DownloadVersionCheck>[String]$Version = ([String](Get-MSIInfo -Path $DownloadFile -Property ProductVersion)).TrimStart().TrimEnd()
        $Version = ($version.Split('.'))[0..1] -join "."</DownloadVersionCheck>
    <Download DeploymentType="DeploymentType2">
        <PrefetchScript>$URL = "$((Invoke-WebRequest |Select -ExpandProperty Links |where -Property href -like "*.msi")[0].href)"</PrefetchScript>
        <DownloadVersionCheck>[String]$Version = ([String](Get-MSIInfo -Path $DownloadFile -Property ProductVersion)).TrimStart().TrimEnd()
        $Version = ($version.Split('.'))[0..1] -join "."</DownloadVersionCheck>

The Downloads Node for 7-Zip has a bit more going on than the Application Node. Upon initial inspection, we can see that there are 2 “DeploymentType(s)” specified, one is tied to “DeploymentType1”, and the other is tied to “DeploymentType2”. We can also tell pretty quickly based on the “DownloadFileName(s)” properties of these downloads that they download the 64-bit and 32-bit msi installers of 7-Zip respectively.

You will notice that a URL is not provided in either of the downloads, however, each download has a “PrefetchScript”, that sets a variable called “$URL”. Let’s look at what the “PrefetchScript” in the “DeploymentType1” download does:

$URL = "$((Invoke-WebRequest |Select -ExpandProperty Links |where -Property href -like "*-x64.msi")[0].href)"

We can see that this script is setting a $URL variable, it just so happens that the $URL variable is tied to the URL tag in the recipe, which is what the SCCM Application Packager Script will attempt to download. That means that whatever we set $URL to in the prefetch script will be downloaded by the Packager Script. If we break down the command a bit more, and run the command found in the inner-most parenthesis in PowerShell:

PS C:\Users\Andrew> (Invoke-WebRequest |Select -ExpandProperty Links |where -Property href -like "*-x64.msi")

innerHTML : Download
innerText : Download
outerHTML : <A href="a/7z1900-x64.msi">Download</A>
outerText : Download
tagName   : A
href      : a/7z1900-x64.msi
innerHTML : Download
innerText : Download
outerHTML : <A href="a/7z1604-x64.msi">Download</A>
outerText : Download
tagName   : A
href      : a/7z1604-x64.msi
innerHTML : Download
innerText : Download
outerHTML : <A href="a/7z920-x64.msi">Download</A>
outerText : Download
tagName   : A
href      : a/7z920-x64.msi

we will see that it returns 3 possible download links to 7-Zip MSIs. If we expand a bit and run everything found in the outer-most parenthesis:

PS C:\Users\Andrew> $((Invoke-WebRequest |Select -ExpandProperty Links |where -Property href -like "*-x64.msi")[0].href) 

we are greeted with a file path for the latest 7-Zip MSI file. Finally, if we run the entire “PrefetchScript” script block:

PS C:\Users\Andrew> $URL = "$((Invoke-WebRequest |Select -ExpandProperty Links |where -Property href -like "*-x64.msi")[0].href)"
PS C:\Users\Andrew> Write-Output $URL

we can see that it returns a full URL. If we go ahead and point our browser to that $URL, we can see that it is a direct download of the latest 7-Zip MSI file. This clarifies the purpose of the “PrefetchScript” Property, it allows the Packager to find the latest download link, even when a hotlink to the latest version is not provided. Crafting a good “PrefetchScript” is one of the harder things to do when creating a recipe, it can take much trial and error. A suggestion for creating a “PrefetchScript” is to build it outside of the packager, and only add it in once it is perfected as it’s own little script.

Moving on, the final thing we will look at in the Downloads Node is the “DownloadVersionCheck”. This property is also just a PowerShell script block. The goal of the “DownloadVersionCheck” is to provide the proper version of the application to the Packager so that it can determine if this download is a new version, and package it if it is new. The “DownloadVersionCheck” script for this recipe is fairly simple:

[String]$Version = ([String](Get-MSIInfo -Path $DownloadFile -Property ProductVersion)).TrimStart().TrimEnd()
$Version = ($version.Split('.'))[0..1] -join "."

First, the “ProductVersion” is grabbed by the “Get-MSIInfo” function, any leading or following white space is trimmed, and the string is saved to the “$Version” variable. Now, this version string will be something like “” which is great and all, but 7-Zip does not even use the last two 0’s on their version string. So, for the sake of consistency with the vendor, we split the “” version string by the “.” and only keep the first two array values (“19” and “0”), then we join those back together with a “.” and assign the joined string back to “$Version”.

Now you may notice, just like there is a $URL that corresponds to the URL tag in the XML, there is also a “Version” tag in the XML; if you were thinking that the “$Version” variable ties to the “Version” tag in the XML, you would be exactly right! It is also important to note that having a Version assigned to every application packaged is a very important aspect to the packaging process. The “Version” property plays an important role, not only in the naming of the application, but in the folder structure on the application share.

7-Zip Deployment Types Node

    <DeploymentType Name="DeploymentType1">
        <DeploymentTypeName>7Zip Silent Install x64</DeploymentTypeName>
        <Comments>Silent Installer for 7Zip</Comments>
            <RuleName>Existential of AutoPackage - OSArchitecture x64 Not Equal to 0</RuleName>
    <DeploymentType Name="DeploymentType2">
        <DeploymentTypeName>7Zip Silent Install x86</DeploymentTypeName>
        <Comments>Silent Installer for 7Zip</Comments>

Alright here we are, the meat of the Recipe. The Deployment Types Node usually ends up being the largest part of any Recipe (depending of course on how tough it is to scrape the latest download for an application).

Looking over the Deployment Types Node, we can see that there are two “DeploymentType” objects with the names “DeploymentType1” and “DeploymentType2”, which correspond with the downloads we saw earlier with the same names. There is also a “DeploymentTypeName” specified in each deployment type, but don’t let that fool you, the “DeploymentTypeName” tag only specifies the name of the deployment type in SCCM. Looking over the rest of the deployment type properties, most of the options should look familiar if you have ever created an application in SCCM before.

We can also see that the 64-bit deployment type has a “Requirements” tag with an associated “RuleName”. These properties specify that a requirements rule with the name “Existential of AutoPackage – OSArchitecture x64 Not Equal to 0” should be added to the application. By default, on it’s first run, the SCCM Application Packager Script will create a few Global Conditions for use when packaging; one of which is “Existential of AutoPackage – OSArchitecture x64” which returns a “1” on a 64-bit operating system. Therefore, this rule will ensure that the 64-bit version will only install on 64-bit computers, while the 32-bit install will run on anything else.

Some other options of note for this recipe are:

  • InstallationType – This sets the type of installation for the deployment type. The MSI “DeploymentType” is nice because if you provide an MSI, SCCM will automatically provide things like Install/Uninstall commands and a detection method. You will notice that specific install and uninstall commands are not specified in this recipe, however they can be added to MSI deployment types in the Packager
  • InstallationMSI – This is the MSI provided to SCCM for it to generate the Install/Uninstall commands and the detection method
  • DetectionMethodType – This specifies that the MSI file should be used to generate the detection method automatically, instead of using a script, file, or registry key for the detection method

7-Zip Distribution Node


Now that we have covered all of the complex parts of the recipe, we can end on a much more gentle note. The Distribution Node for the 7-Zip application only contains a single property. The “DistributeContent” property for 7-Zip is set to “True” meaning it will be distributed to the default distribution point group specified in the preferences file.

7-Zip Deployment Node


Last but not least, the Deployment Node for the 7-Zip recipe also contains just a single Property. The “DeploySoftware” property here is also set to “True” meaning the software will be deployed as available to the default collection specified in the preferences file. I will note that this is the default for all of the recipes provided, but can be changed per recipe depending on your specific needs.

7-Zip Application End Result

This post went a bit long, so I am going to let the results speak for themselves here:

This slideshow requires JavaScript.

The SCCM Application Packager Script is a very powerful tool. Its recipes were designed for ultimate flexibility with the intention of automating the packaging of just about any application in SCCM. Creating your own recipes can be a time consuming process, however, the end result will end up saving a ton of time. In my own production environment, I have saved an estimated 220 hours a year with this tool, and that number will only grow as more recipes are created, and more application updates are released per month.

Thank you for taking the time to read this post and your interest in the SCCM Packager Script! I created this tool with the intention of saving people time and energy, and was able to deepen my knowledge in SCCM and PowerShell as a result. If you are interested in contributing your own recipes to the project, feel free to submit pull requests to the GitHub repository.

Andrew Jimenez

Twitter: @AndrewJimenez_

Package Software While You Sleep Using the SCCM Application Packager Script

, , , , ,

Don’t you love when Chrome, Firefox and Flash all release critical updates all at the same time? Packaging software that changes frequently was taking a lot of my time, I knew that there must be a better way. I search for solutions, but found nothing that satisfied my needs at the time. In the end, I decided to create my own solution. This solution became a powerful PowerShell script that required nothing but the internet, a console connection and the built-in ConfigurationManager module. The SCCM Application Packager script takes the work out of packaging applications by automating the Download, Packaging, Distribution and Deployment of applications using flexible XML files called “recipes”. The script is open source and available on GitHub for anyone to use! In this post I’ll go over the process of setting up the script so you can package applications while you sleep!


We’ll start with a few prerequisites. You will need at least the following to get started with the scripts:

  • Computer that will do the packaging should have access to the SCCM Primary Site and the internet to download packages
  • SCCM Console installed and it is recommended, but not required, to connect to your site through the console at least once
  • I also recommend opening Internet Explorer once and going through the initial setup. This allows the script to download the applications without running into blocks

After you have confirmed you have the proper setup to run the script, you can begin downloading the script and setting up the preferences for your site.

Download the SCCM Application Packager tool from GitHub

  1. You can download directly from GitHub here:
  2. Unzip the downloaded file at a location of your choosing, I chose “C:\”.
  3. Navigate to “C:\SCCM-Application-Packager-master” and open the “SCCMPackager.prefs” file.

Setting up the SCCM Application Packager tool

  1. Set the ContentLocationRoot to your SCCM Content Folder. The script will create a folder for each application in this Content Folder.
  2. Set the IconRepo to the location where you store all of your icons if you don’t have an icon folder many are included with the Application Packager tool in the “ExtraFiles\icons” folder.
  3. Set the SCCMSite to your SCCM Site Code (Don’t forget the “:” at the end).
  4. If you would like an email sent at the end of the packaging, you can set the email preferences, otherwise set “SendEmailPrefences” and “NotifyOnDownloadFailure” to False
  5. Set the PreferredDistributionLoc to a Distribution Point Group that you want packages to be distributed by default
  6. Set the PreferredDeployCollection to a collection that you want packages to be deployed to by default

Running the initial setup

This creates an Application and some Global Conditions that the script uses as a template for requirements rules and install behavior

  1. Open a PowerShell Window in the SCCM Application Packager Directory and run the “SCCMPackager.ps1” script. Typing “powershell” in the location bar will automatically open PowerShell in the current directory.
  2. While the script is running, you can follow along by watching the log file, which is located by default at “C:\Temp\SCCMPackager”
  3. When the script has completed it’s first run, the log file will provide instructions on how to proceed. These extra steps allow the script to create applications that use Install Behaviors. Simply open your Configuration Manager Console and add an install behavior to the Application Requirements Template.
  4. Please note that some applications require the 7za executable from the 7-zip project to be packaged. I recommend downloading 7zip-extra from and copying the “7za.exe” file from there into the root of your SCCM Application Packager folder before continuing.
  5. You may also want to take advantage of the application icons that have already been specified in the Application Packager. There are application icons included for every recipe provided on the GitHub. Those can be found in the “ExtraFiles\icons” folder. I would recommend copying them to the “IconRepo” specified in step 2.
  6. Initial Setup is now complete! Time to package some Applications!

Packaging Applications

Once the initial setup is complete, packaging applications is as simple as copying or moving some files to a folder and running the script!

  1. Navigate to the SCCM Application Packager Script directory.
  2. Look through the “Disabled” folder and determine what XML files (called “recipes”) you want to package.
  3. Cut or Copy the recipes that you want to package from the “Disabled” folder into the “Recipes” folder.
  4. Run the “SCCMPackager.ps1” script using PowerShell, just as you did during the Initial Setup
  5. Sit back and relax! You can always look at the log file to see how packaging is proceeding. Once packaging is finished, it is always good to test the packaged apps to ensure they deploy and function in the way you expect. The applications the script creates will be fully featured, including icons, descriptions, estimated and max install times, and take advantage of requirements and Install behavior if needed.
    SCCM Application Packager

Automate packaging

Once the script is in good working order, I prefer to have everything happen automatically. My current preferred method of doing so is using the built-in Windows Task Scheduler to run the script weekly at 4 AM on Wednesday mornings. Feel free to adjust the schedule to your specific needs and goals.

  1. Open the Task Scheduler, and navigate to the Task Scheduler Library (I just search for it in the start menu, but you can go through MMC if you are feeling fancy.)
  2. Right click and create a new Basic Task.
  3. General Tab

    1. Name: “SCCM Application Packager” has a nice ring to it
    2. A Description of your choosing
    3. Choose the user account you want to run the script with, here I chose my regular user account, but in my Production environment I have a service account dedicated to the task (just make sure you log in with the service account and ensure it has done the IE setup and can get to the Console)
    4. Choose the “Run whether user is logged on or not” radio button.
    5. Some apps require the application be installed and uninstalled to figure out the version numbers and other information, so you may want to check the box to “Run with highest privileges” if any of your recipes require it.
  4. Triggers Tab

    1. Click “New…”, and choose: Run: “On a schedule”
    2. I chose Weekly at 4 AM on Wednesday.
    3. Stop the task if it runs longer than 2 hours
    4. Click “OK”
  5. Actions Tab

    1. Click “New…”, and choose “Start a program” as your Action
    2. Program/script: powershell.exe
    3. Add arguments: -executionpolicy bypass -file “C:\Path\To\SCCMPackager.ps1”
    4. Click “OK”
  6. Conditions

    1. The only condition I would check on this page may be “Start only if the following network connection is available” Otherwise, leave everything unchecked
  7. Settings

    1. Check “Allow task to be run on demand” (We will use this for testing)
    2. Stop the task if it runs longer than: ” hours”
    3. If the task is already running: “Do not start a new instance”
  8. Once the Scheduled Task is set up click OK, and enter your username and password to save the credentials to run if you aren’t logged in.
  9. Finally, right-click the newly created task and click “Run”, then watch the log file to ensure it is running properly.


That’s it! After everything is set up and you have the scheduled task created, the script will run when scheduled and download, package, distribute, and deploy your applications to your specified collection. All you have to do is test and deploy to production! If you set up the email feature, the script will email you a report of newly packaged applications and if it ran into any errors in the process.

If you think the SCCM Application Packager tool would make your life easier, you can find it at GitHub here: I also happily accept pull requests with new features, or for recipes. If you are interested in creating recipes, stick around for Part 2, where I will go over how the script and recipes work!

Thank you for reading this post! I hope this script helps save a lot of time and headaches!


Andrew Jimenez

Twitter: @AndrewJimenez_