PowerShell scripting template for SCCM packages

An SCCM package is basically a container with source files. I recommend using a wrapper (a script) to execute the installation files. What you need is a PowerShell scripting template for SCCM or a deployment framework for SCCM.

Change Log
23.05.2017: Updated and renamed functions.

You can create your own wrapper or you can use an open source deployment tool. For larger enterprises, I recommend using the PowerShell App Deployment Toolkit (http://psappdeploytoolkit.com). This toolkit is an open source project launched in 2013 by PowerShell wizards Seán Lillis and Dan Cunningham. It is basically a deployment framework based on a collection of PowerShell scripts, with a graphical user interface prepared for multiple languages. It also includes many ready-to-use functions.
The framework also allows you to add your own custom functions. These are stored in a separate PowerShell script. When you update to the latest version of ADT, you simply copy this PowerShell script to the new ADT version and that's it!

In case you are looking for a more simple solution I have prepared a small PowerShell (AppInstaller.ps1) script which allows you to install and uninstall your software. This script serves as an example. You can (and most likely will have to) extend it yourself.

Copy the above code in your preferred editor (e.g. notepad) and store the file as AppInstaller.ps1 (or use a different name if you want to).

This above PowerShell script contains two functions:

  • DS_WriteLog -> this function handles all logging
  • DS_InstallOrUninstallSoftware -> this function handles all installation and uninstallations

This script is designed to work with SCCM packages. You only need to modify a couple of lines in the script:

Lines 186 and 187:
Enter your preferred log directory and package name. For example:

  • $BaseLogDir = "C:\Logs"
  • $PackageName = "Adobe Acrobat Reader"

When the log directory is created, spaces are automatically replaced with an underscore ("_"), for example: C:\Logs\Adobe_Acrobat_Reader.


Changing the main log directory (e.g. C:\Logs) at a later time means that you have to change each script that contains the hard-coded path. There is another, more flexible way:

  • Create an environment variable using a Group Policy Preference called GlobalLogPath (or use a different name). As a value enter your preferred log path, for example "C:\Logs".
  • In the script, add $env:GlobalLogPath as a value to the PowerShell variable $BaseLogDir: $BaseLogDir = $env:GlobalLogPath

The PowerShell script now reads the log path from the environment variable GlobalLogPath. In case you ever want to change the log directory you simply change the path in the Group Policy Preference environment variable without having to change any of your scripts.

Lines 216, 218, 220 and 222:
Enter the name of your (un)installation file, arguments and SCCM package sub folder. For example:

  • $FileName = "AcrobatReader.msi"
  • $Arguments =
    • "Transforms=""AcrobatReader.mst"" LANG_LIST=""en_US,de_DE"""
    • "/silent /uninstall"
    • "/QN" (for setup.exe files only)
  • $FileSubFolder = "Files", or "MSI", or "SETUP", or anything else

The subfolder is the relative path to your package source directory. For example, if this is your package source folder:

\\FileServer1\PackageSource\Adobe\Acrobat Reader\11.0.18_01

Than the subfolder for your installation source files is:

  • \\FileServer1\PackageSource\Adobe\Acrobat Reader\11.0.18_01\Files
    \\FileServer1\PackageSource\Adobe\Acrobat Reader\11.0.18_01\MSI
  • \\FileServer1\PackageSource\Adobe\Acrobat Reader\11.0.18_01\SETUP

Please note that for MSI packages the following parameters are added by default:

  • For uninstallations: "/x ""$File"" /qn /norestart /l*v ""$LogFileAPP"""
  • For installations: "/i ""$File"" /qn /norestart /l*v ""$LogFileAPP"""

When you have prepared your PowerShell file copy it in the root of your package source directory. For example:

\\FileServer1\PackageSource\Adobe\Acrobat Reader\11.0.18_01\AppInstaller.ps1

The PowerShell script is executed as follows:

  • For installations:
    powershell -file "\\FileServer1\PackageSource\Adobe\Acrobat Reader\11.0.18_01\AppInstaller.ps1" Install
  • For uninstallations:
    powershell -file "\\FileServer1\PackageSource\Adobe\Acrobat Reader\11.0.18_01\AppInstaller.ps1" Uninstall

Happy scripting!

Share this post:
Dennis Span on EmailDennis Span on LinkedinDennis Span on Twitter
Dennis Span
Dennis Span
Dennis Span works as a Senior Citrix Architect for a large insurance company in Vienna, Austria. He holds multiple certifications such as CCE-V, CCIA and CCEA. In 2017, Dennis became a Citrix Technology Advocate (CTA). Besides his interest in virtualization technologies and blogging, he loves spending time with his family as well as snowboarding, playing basketball and rowing. He is fluent in Dutch, English, German and Slovak and speaks some Spanish.

11 thoughts on “PowerShell scripting template for SCCM packages

    • Hi Phil, for sure it works with MDT as well. I do not add any SCCM specific functions in my PowerShell scripts. My scripts also work without SCCM or MDT. You can simply trigger them manually (e.g. powershell.exe -file %FileName%).

  1. Pingback: Google Chrome on Citrix deep-dive - Dennis Span

  2. Pingback: Scripting the complete list of Citrix components with PowerShell - Dennis Span

  3. Pingback: Printer Drivers Installation and Troubleshooting Guide - Dennis Span

  4. Pingback: Citrix Delivery Controller unattended installation with PowerShell and SCCM - Dennis Span

  5. Pingback: Citrix License Server unattended installation with PowerShell and SCCM - Dennis Span

  6. Pingback: Citrix Provisioning Server unattended installation - Dennis Span

  7. Pingback: Citrix Director unattended installation with PowerShell - Dennis Span

  8. Pingback: Citrix App Layering Agent unattended installation - Dennis Span

  9. Pingback: How to configure and run BIS-F in an SCCM task sequence - Dennis Span

Leave a Reply

Your email address will not be published.