Use start-cmContentDistribution to get content status

aj-47 66 Reputation points

A part of the script logic is as follows

    `#load config mgr module`
    `# set-location to sitecode`
    `# create pkg source dir`
    `# add content to pkg source dir`
    `# create pkg, pkg program`

Next step is to use start-cmContentDistribution
I was wondering if there is anyway for the script to halt/suspend execution until package content is successfully distributed to all DPs
Have tried the following to no help:

$job = start-job -scriptBlock {start-cmContentDistribution -packageID 'abc123' -distributionPointGroupName 'dpGrp1' } 
wait-job $job
$res = receive-job $job -keep

In former case, control moves over to the line after start-cmContentDistribution cmdlet after initiating distribution, in the latter the $job variable shows a status of 'complete', without initiating distribution.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
4,745 questions
Microsoft Configuration Manager
No comments
{count} votes

Accepted answer
  1. AlexZhu-MSFT 3,696 Reputation points Microsoft Vendor


    Hope the below script helps. If we get the "completed" value of $distribution_status, we can continue other tasks

    $Time1 = Get-Date  
    start-cmContentDistribution -packageID 'test03' -distributionPointGroupName 'dpGrp1'  
    $PackageId = (Get-CMApplication -Name 'test03').PackageID  
    $distribution_status = "started"  
    #if the distribution is not completed within 2 hours, exit the loop  
    while($timediff.totalminutes -lt 120)  
     $Time2 = Get-Date  
     $TimeDiff = New-TimeSpan $Time1 $Time2  
     $all_finished = (Get-CMDistributionStatus -Id $PackageId).numbersuccess -eq (Get-CMDistributionStatus -Id $PackageId).targeted  
     if ($all_finished)  
     $distribution_status = "completed"  
     start-sleep -s 300  
     #"sleeping 5 minutes ..."  
    write-host $distribution_status  
    # other tasks  


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

0 additional answers

Sort by: Most helpful