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
- You can download directly from GitHub here: https://github.com/asjimene/SCCM-Application-Packager
- Unzip the downloaded file at a location of your choosing, I chose “C:\”.
- Navigate to “C:\SCCM-Application-Packager-master” and open the “SCCMPackager.prefs” file.
- Set the ContentLocationRoot to your SCCM Content Folder. The script will create a folder for each application in this Content Folder.
- 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.
- Set the SCCMSite to your SCCM Site Code (Don’t forget the “:” at the end).
- 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
- Set the PreferredDistributionLoc to a Distribution Point Group that you want packages to be distributed by default
- 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
- 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.
- While the script is running, you can follow along by watching the log file, which is located by default at “C:\Temp\SCCMPackager”
- 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.
- Please note that some applications require the 7za executable from the 7-zip project to be packaged. I recommend downloading 7zip-extra from https://www.7-zip.org/download.html and copying the “7za.exe” file from there into the root of your SCCM Application Packager folder before continuing.
- 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.
- Initial Setup is now complete! Time to package some 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!
- Navigate to the SCCM Application Packager Script directory.
- Look through the “Disabled” folder and determine what XML files (called “recipes”) you want to package.
- Cut or Copy the recipes that you want to package from the “Disabled” folder into the “Recipes” folder.
- Run the “SCCMPackager.ps1” script using PowerShell, just as you did during the Initial Setup
- 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.
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.
- 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.)
- Right click and create a new Basic Task.
- General Tab
- Name: “SCCM Application Packager” has a nice ring to it
- A Description of your choosing
- 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)
- Choose the “Run whether user is logged on or not” radio button.
- 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.
- Triggers Tab
- Click “New…”, and choose: Run: “On a schedule”
- I chose Weekly at 4 AM on Wednesday.
- Stop the task if it runs longer than 2 hours
- Click “OK”
- Actions Tab
- Click “New…”, and choose “Start a program” as your Action
- Program/script: powershell.exe
- Add arguments: -executionpolicy bypass -file “C:\Path\To\SCCMPackager.ps1”
- Click “OK”
- The only condition I would check on this page may be “Start only if the following network connection is available” Otherwise, leave everything unchecked
- Check “Allow task to be run on demand” (We will use this for testing)
- Stop the task if it runs longer than: ” hours”
- If the task is already running: “Do not start a new instance”
- 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.
- 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: https://github.com/asjimene/SCCM-Application-Packager. 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!