Menu
CCMEXEC.COM – Enterprise Mobility
  • Home
  • General
  • Configuration Manager
  • Windows 10
  • Windows 11
  • Intune
  • GitHub
  • About
CCMEXEC.COM – Enterprise Mobility

Installing applications and packages dynamically during OSD

Posted on December 11, 2017December 11, 2017 by Jörgen Nilsson

I wrote a post way back where I used a Powershell script to query AD group description for Applications to install dynamically during OS deployment in Configuration Manager. There was a couple of comments and recently a request to extend that script to also install packages dynamically during OS Deployment. The old post can be read here: https://ccmexec.com/2016/05/installing-applications-dynamically-during-os-using-ad-group/

So here it is as promised, this script will install both applications and packages/programs during OS deployment dynamically.

It will read the description of AD groups and match it using a Prefix and Suffix to identify groups used for Applications / Packages. In the Description field for AD groups used for applications we add the application name and for packages we the packageID and program to run like shown below.

To use it:

  1. Save the script below and edit the following lines so it matches the environment it is run in
    $Prefix = “A.”
    $Suffix = “.i”
    $SiteCode = “060”
  2. Create a package with the script so we can run it in a Task Sequence
  3. Add the script to the Task Sequence using the run Powershell script command
  4. Add an Install Application Step using these settings.

    With the following condition so it is skipped if the are no applications to install
  5. Add an Install Packages Step using these settings.

    With the following condition so it is skipped if there are no packages to install

 

The script:

# Written by Johan Schrewelius / Jörgen Nilsson
# https://ccmexec.com
# Version 1.1
# Added fallback to _SMSTSMAchineName if OSDComputerName is missing
# Thanks to Daniel Marklund for testing and adding features (Nested groups)!
# Version 1.2
# Update 2/12/2017: Added support for PackageID:Program in description attribute – Limitation: Application name must not start with SiteCode

$Prefix = “A.”
$Suffix = “.i”
$SiteCode = “060”

$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment

$CmpName = $tsenv.Value(“OSDComputerName”)
if(!$CmpName) { $CmpName = $tsenv.Value(“_SMSTSMachineName”) }

$ADObjectDN = ([ADSISEARCHER]”samaccountname=$($CmpName)`$”).Findone().Properties.distinguishedname
$AllGroups =([ADSISEARCHER]”member:1.2.840.113556.1.4.1941:=$ADObjectDN”).FindAll()

$DescList = $AllGroups.Path `
| Where { ($_ -replace ‘^LDAP://CN=([^,]+).+$’,’$1′).StartsWith($Prefix) -and ($_ -replace ‘^LDAP://CN=([^,]+).+$’,’$1′).EndsWith($Suffix) } `
| Foreach { ([ADSI]”$_”).Description }

$AppCount = 1
$PkgCount = 1

$DescList | Where { !$_.StartsWith($SiteCode) } | Foreach { $tsenv.Value(“COALESCEDAPPS” + ($AppCount++).ToString(“00”)) = “$_” }
$DescList | Where { $_.StartsWith($SiteCode) } | Foreach { $tsenv.Value(“PACKAGES” + ($PkgCount++).ToString(“000”)) = “$_” }

That is it.

2 thoughts on “Installing applications and packages dynamically during OSD”

  1. Bruno Bertelli says:
    September 26, 2018 at 5:17 pm

    Hi Jörgen , thanks for this post, very usefull.
    What if the application is deployed by a task sequence ? It will work?
    Regards
    Bruno

    Reply
    1. Jörgen Nilsson says:
      September 28, 2018 at 11:35 am

      Hi,
      You would have to use Nested task sequences in that case if the order is important.
      /Jörgen

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

My name is Jörgen Nilsson and I work as a Senior Consultant at Onevinn in Malmö, Sweden. This is my blog where I will share tips and stuff for my own and everyone elses use on Enterprise Mobility and Windows related topics.
All code is provided "AS-IS" with no warranties.

Recent Posts

  • Tip when troubleshooting unexpected reboots during Autopilot – event ID 2800
  • New settings in Intune Security Baseline Windows 11 24H2 -2504
  • Managing extensions in Visual Studio Code
  • Reinstall a required Win32app using remediation on demand
  • Administrator protection in Windows 11 – First look
©2025 CCMEXEC.COM – Enterprise Mobility | WordPress Theme by Superb Themes
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.Accept Reject Read More
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT