SCCM Configmgr Powershell Script Redistribute package on Multiple Distribution Points

Powershell Scripting made things lot more easier in Configuration Manager 2012.You can automate console operations by using Windows PowerShell cmdlets.For list of Configmgr SP1 cmdlets,refer http://technet.microsoft.com/en-us/library/jj821831(v=sc.10).aspx

Manually Refresh of the Distribution Points for a specific package in Configmgr 2012 is not easy as it was in CM07.

Started using the Powershell script for simple tasks such as Redistribute,updating,adding Distribution points.

Use the below script to refresh failed package on Multiple Distribution Points.

 

import-module F:\sccm\AdminConsole\bin\ConfigurationManager.psd1
$SiteCode = "ESK"
$DPserver =GC "C:\Script\Servers.txt"
foreach ($Server in $DPserver)
{
$PackageID = "ESK00001"
$distpoints = Get-WmiObject -Namespace "root\SMS\Site_$($SiteCode)" -Query "Select * From SMS_DistributionPoint WHERE PackageID='$PackageID' and serverNALPath like '%$Server%'"
foreach ($dp in $distpoints)
{
$dp.RefreshNow = $true
$dp.Put()
"Pkg:" + $PackageID + " "+ "Refreshed On" + " "+ "Server:" +$server | Out-File -FilePath C:\Script\refresh-results.txt -Append
}
}

Monitor distmgr.log(if the package is refreshed or not),sender.log on the primary site (if your DP is secondary),pkgXfermgr.log (If your DP is remote DP) for any errors.

Note:Replace the Quotes when you copy the Code.

You can also download the script from technet gallary here

More Scripts coming on the way 😉

5 Responses to "SCCM Configmgr Powershell Script Redistribute package on Multiple Distribution Points"

  1. Hi Eswar,

    Im trying to update content for the application having multiple Deployment types and tried with the following script:

    Import-Module "C:\Program Files (x86)\Microsoft Configuration Manager Console\AdminConsole\bin\ConfigurationManager.psd1"

    $ApplicationName =Read-host("mention the app name")
    #Input parameters
    $sitecode = "Sitecode"
    CD $sitecode":"
    $ApplicationCI=(Get-CMApplication -Name $ApplicationName).CI_ID

    If ($ApplicationCI -eq $Null)
    {
    Write-host "sorry"
    }

    Else
    {

    $dptypes=get-cmdeploymenttype -ApplicationName $ApplicationName
    $x= $dptypes.LocalizedDisplayName
    foreach ($y in $x)
    {
    Update-CMDistributionPoint -ApplicationName $ApplicationName -DeploymentTypeName $y }
    }

    The above script end with error in deployment type check ,Unfortunately it is updating the first deployment type of the application and deleting the remaining deployment types.. 🙁

    I tried passing the deloyent type name directly, it is taking correctly, but when i use foreach loop and get the inputs as array, it is ending up with error.
    Can you provide your suggestions on this ?

    Reply
  2. i tried the above PS to redistribute an application with its package id to multiple Distribution points i got the error

    Exception calling "Put" with "0" argument(s): "Generic failure "
    At line:14 char:13
    + $dp.Put()
    + ~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

    how to get this done?

    Reply
    1. seems like put command is not recognised,did you import the cm module and changed the sitecode ? also i would request to change the quotes ('")

      Reply

Post Comment