Configmgr 2012 Powershell script add packages applications Drivers to Distribution Point

In my previous blog post,i talked about how to compare 2 distribution points to see if they both have any applications mismatch.This blog post talks about how to distribute the missing apps to the Distribution Point.

I have used basic inbuilt Configmgr powershell commands for this activity,more via here

Note:Use the package names as input file rather Package ID’s.

Below powershell script works for applications,packages,driver packages,boot images and OS images.You need to remove the # tag(to uncomment) to distribute specific package type.

#change the path of psd1
import-module F:\sccm\AdminConsole\bin\ConfigurationManager.psd1
#Change the site Code
cd P01:
$SiteCode = "P01"
#provide the path for list of applications to be distributed
$packages =GC "C:\users\eswar\desktop\pkglist.txt"
$server='DPname.eskonr.com'
foreach ($packagename in $packages)
{
#for applications
#Start-CMContentDistribution -ApplicationName  "$packagename" -DistributionPointName "$server"

#For packages
#Start-CMContentDistribution -PackageName  "$packagename" -DistributionPointName "$server"

#For Driverpackage names
#Start-CMContentDistribution -DriverPackageName  "$packagename" -DistributionPointName "$server"

#For Bootimages
#Start-CMContentDistribution -BootImageName  "$packagename" -DistributionPointName "$server"

#For OSImages
#Start-CMContentDistribution --OperatingSystemImageName  "$packagename" -DistributionPointName "$server"

#output results

"Pkg:" + $packagename + " "+ "distributed to" + " "+ "Server:" +$server | Out-File -FilePath C:\users\eswar\desktop\server-distribute-results.txt -Append
}

download the powershell script from technet Gallery

How to refresh package on many DP’s : http://eskonr.com/2013/09/sccm-configmgr-powershell-script-refresh-package-on-multiple-distribution-points/

13 Responses to "Configmgr 2012 Powershell script add packages applications Drivers to Distribution Point"

  1. Thanks for the script but unfortunately this one is not working for me.... i have changed the site code, servername & path but still it wont work. Below is the error that i get:

    Start-CMContentDistribution : No object corresponds to the specified parameters.
    At E:\appdp\AddPkg.ps1:6 char:1
    + Start-CMContentDistribution -ApplicationName "$packagename" -DistributionPointN ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (Microsoft.Confi...ributionCommand:StartContentDistributionCommand) [Sta
    rt-CMContentDistribution], ItemNotFoundException
    + FullyQualifiedErrorId : ItemNotFound,Microsoft.ConfigurationManagement.Cmdlets.Sum.Commands.StartContentDistribu
    tionCommand

    Start-CMContentDistribution : No object corresponds to the specified parameters.
    At E:\appdp\AddPkg.ps1:9 char:1
    + Start-CMContentDistribution -PackageName "$packagename" -DistributionPointName ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (Microsoft.Confi...ributionCommand:StartContentDistributionCommand) [Sta
    rt-CMContentDistribution], ItemNotFoundException
    + FullyQualifiedErrorId : ItemNotFound,Microsoft.ConfigurationManagement.Cmdlets.Sum.Commands.StartContentDistribu
    tionCommand

    Start-CMContentDistribution : No object corresponds to the specified parameters.
    At E:\appdp\AddPkg.ps1:12 char:1
    + Start-CMContentDistribution -DriverPackageName "$packagename" -DistributionPoin ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (Microsoft.Confi...ributionCommand:StartContentDistributionCommand) [Sta
    rt-CMContentDistribution], ItemNotFoundException
    + FullyQualifiedErrorId : ItemNotFound,Microsoft.ConfigurationManagement.Cmdlets.Sum.Commands.StartContentDistribu
    tionCommand

    Out-File : Could not find a part of the path 'C:\users\eswar\desktop\server-distribute-results.txt'.
    At E:\appdp\AddPkg.ps1:16 char:75
    + "Pkg:" + $packagename + " "+ "distributed to" + " "+ "Server:" +$server | Out-Fi ...
    + ~~~~~~
    + CategoryInfo : OpenError: (:) [Out-File], DirectoryNotFoundException
    + FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand

    Reply
  2. Eswar - Thanks for all your answers so far. We did open a case with premier, and found that this cmdlet is broken. This has been fixed in R2. But as we are going live soon, we can't implement R2. No other options so far..
    Thanks once again for your help. Just wanted to update you and what we found from Microsoft Premier.

    Reply
      1. senthamarai kannan · Edit

        Hi Eswar,

        I'm trying to use our script to add package to DP, in our Environment we have DP and BDP comes under the same site code, but what i wanted to do is, add multiple listed packages to the only DP list given the text file so that we can avoid BDP, is that any script you have to help us ?
        that would be much appreciated 🙂

        Reply
          1. Thanks for the quick reply eswar, i was using the below script,

            $SiteCode = "QA4"

            #provide the path list of packages to be Refreshed

            $packages =GC "C:\Kannan\pkglist.txt"
            foreach ($package in $packages)
            {
            #Provide the list of DP server Name to be refreshed ON
            Write-Host "Processing Package $package"

            $DPs = GC "C:\Kannan\DPlist.txt"
            foreach ($server in $DPs)
            {
            $pkg = Get-WmiObject -Namespace "root\SMS\Site_$($SiteCode)" -Query "Select * From SMS_DistributionPoint WHERE PackageID='$Package' and serverNALPath like '%$Server%'"

            $pkg.put_

            Write-Host "Package Refreshed On Server : $server"
            "Pkg:" + $package + " "+ "Refreshed On" + " "+ "Server:" +$server | Out-File -FilePath "server-refresh-results.txt" -Append
            }
            }

            Once the script is completed i can the output file stating that all packages are refreshed, but when i checked the log distmgr.log, none of the packages are not added, this is for 2007 environment, Kindly check if any mistakes are changes has to be done please do,

            Reply
  3. Right now we can upgrade from the console. But we can select only one site out of the 3 we have. We have around 600 secondary sites, which are going to be Remote distribution point. So desperately trying to find a solution as how we can use powershell to upgrade these 2007 secondary sites to 2012 remote DP's..

    Reply

Leave a Reply