web analytics

Blog

How to invoke a Package Redistribution

Posted by:

To invoke a Package Redistribution

  1. Set up a connection to the SMS Provider.
  2. Query a Distribution Point Group from SMS_DistributionPointGroup WMI class
  3. Use the ReDistributePackage method.
  4. Set the PackageID property.
  5. Depending on the configuration, set the correct value

Examples

Example Output

You can download the code examples from here



About the Author:

Kaido Järvemets is a developer, consultant, trainer specializing in Microsoft System Center Configuration Manager and PowerShell Solutions at Coretech. Kaido frequently speaks at European conferences and had his US debut as speaker at MMS April 2013. Kaido is well-known in the Configuration Manager communities where he’s a key player in the PowerShell game. Kaido host one of the most complete Configuration Manager PowerShell library’s in the world with hundreds of free code samples ready to download and implement – www.cm12sdk.net. Kaido has been awarded Microsoft Most Valuable Professional (MVP) in Microsoft Enterprise Client Management for his work with Configuration Manager from 2011 – to present. Kaido is the founder of System Center User Group Estonia in 2011.

Discussion

  1. V.Klaffehn  October 2, 2013

    Hello, I am trying to redistribute an application without success.
    I have an existing application with deployment, now I changed something in the source files and want to update the content of the application like I can do with a right click on the deployment type and selecting ‘update content’, but I need to do that for all our applications, so I want to do it with a script.
    I searched a lot, but it seems I can only refresh the application, but not update it…. any help would be appreciated!!

    (reply)
    • Kaido  October 3, 2013

      Hi,

      Is your package distributed to DP Group?

      Best,

      (reply)
      • V.Klaffehn  October 3, 2013

        Yes, we have two DP’s building one DP Group. I can see in the logs that the package is refreshed on the DP, but not rebuild from the modified source.

        Thanks

        (reply)
        • V.Klaffehn  October 4, 2013

          Oh, btw, these are the things I’ve already tried :

          RedistributePackages
          Remove- and AddPackages and Redistribute
          RefreshPkgSource
          But nothing is working the way I want…
          I don’t get errors, I can see activity in the logs, I can also see the last refresh time in the CM console, but the package contents never change and the revision stays the same.

          Get-Wmiobject -Namespace “root\SMS\Site_$site” -Class SMS_ContentPackage | foreach{
          $name = $_.Name
          echo “redistributing Package $Name to DP group $DPGroup …”
          $PackageID = $_.PackageID
          $DPQuery = Get-WmiObject -Namespace “Root\sms\site_ptb” -Class SMS_DistributionPointGroup -Filter “Name=’$DPGroup'”
          $DPQuery.RedistributePackage($PackageID)
          }

          (reply)
          • V.Klaffehn  October 9, 2013

            Hi, I found out something :
            Using the ‘Redistribute’ button found under “Administration-DP Groups–Properties-Content” actually only refreshes Applications, maybe because there was nothing changed in the application itself. The following powershell script does what I wanted (only caveat is, the revision gets increased):

            try
            {
            $DPGroup = “PTB”
            Get-Wmiobject -Namespace “root\SMS\Site_ptb” -Class SMS_Application -Filter “isLatest=’true’ and isExpired=’false'” | foreach{
            $name = $_.LocalizedDisplayName
            echo “Application : $name”
            $dptypes = Get-CMDeploymentType -ApplicationName “$name”
            foreach ($dpt in $dptypes){
            $dptname = $dpt.LocalizedDisplayName
            echo “Deployment Type: $dptname”
            Update-CMDistributionPoint -ApplicationName “$name” -DeploymentTypeName “$dptname”
            }
            }
            }
            catch
            {
            $_.Exception.Message
            }

  2. prem saagar  December 13, 2013

    how to redistribute application for a single distribution point instead of DP groups?

    (reply)
    • v.klaffehn  May 22, 2014

      Hi, the script should also work on Distribution Points. Its the same like right-clicking on the Application Deployment Type and selecting ‘update content’

      Import-Module ‘C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1′
      cd ptb:
      $apps = Get-CMApplication | where {$_.isexpired -eq $false -and $_.issuperseded -eq $false}
      foreach ($app in $apps)
      {
      $deploymenttypes = Get-CMDeploymentType -ApplicationName $($app.localizedDisplayName)
      foreach ($deploymenttype in $deploymenttypes)
      {
      write-host $deploymenttype
      Update-CMDistributionPoint -ApplicationName $app.LocalizedDisplayName -DeploymentTypeName $deploymenttype.LocalizedDisplayName
      }
      }

      (reply)

Add a Comment