PowerShell Script to distribute packages to DPs if it's not

Shijin121 216 Reputation points
2020-09-26T15:53:54.503+00:00

Hi

I have a requirement to write a PowerShell script to,

  1. Read a list of DPs (Know how to do it)
  2. And Read a list of packages
  3. And then for each DP it will check if each package is already distributed to the DP
  4. If it is it does nothing
  5. If it isn’t, it will distribute the package to the DP.

I'm able to figure out steps 1,2, 4 & 5. I need your help to get the PS cmdlet to check whether the package is distributed or not.

Shijin M

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,619 questions
Microsoft Configuration Manager
No comments
{count} votes

Accepted answer
  1. Shijin121 216 Reputation points
    2020-10-07T13:43:09.187+00:00

    Thanks
    Re-wrote the script like below.

    $x = $null
    $x = Get-CMDeploymentPackage -DistributionPointName "DPName" -DeploymentPackageName "AppName"
    If ($x -ne $null)
    {
    Write-Host "Distributed Already";
    }
    Else
    {
    Write-Host "Not yet Distributed";
    }

    Thanks!!

    No comments

4 additional answers

Sort by: Most helpful
  1. Rich Matheisen 35,031 Reputation points
    2020-09-26T18:13:03.207+00:00

    See the help for the Get-CMDeploymentPackage.

    No comments

  2. Ian Xue (Shanghai Wicresoft Co., Ltd.) 18,351 Reputation points Microsoft Employee
    2020-09-28T02:09:16.463+00:00

    Hi,

    The Get-CMDeploymentPackage cmdlet gets information about deployment packages on a distribution point.

    Get-CMDeploymentPackage -DistributionPointName "YourDPName" -DeploymentPackageName "YourPackageName"  
    

    Get-CMDeploymentPackage
    https://learn.microsoft.com/en-us/powershell/module/configurationmanager/get-cmdeploymentpackage?view=sccm-ps

    Best Regards,
    Ian

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    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.

    No comments

  3. Rich Matheisen 35,031 Reputation points
    2020-10-06T19:34:32.94+00:00

    Try this:

    Try{
        $x = Get-CMDeploymentPackage -DistributionPointName "YourDPName" -DeploymentPackageName "YourPackageName" -ErrorAction STOP
        "Yes"
    }
    Catch{
        "No"
    }
    
    No comments

  4. Shijin121 216 Reputation points
    2020-10-06T13:48:01.187+00:00

    Hi Ian,

    Thanks!!

    It gives output if the package is distributed.

    Is it possible to get an output like

    "Yes" - If the package is distributed.
    "No" - If the package is not distributed.

    Thanks!!

    No comments