Custom SCCM / MECM / ConfigMgr PowerShell script issue

79 views Asked by At

The objective of this PowerShell script is to accept a SCCM / ConfigMgr DP Group as input, & output into .csv file, the list of all unique package IDs distributed to it.

ISSUE: It returns empty output csv file with NO package IDs despite SQL query confirming that content is indeed distributed to the input DP group.

Please help as to what am I missing here? Thank you to all for your valuable time & input into helping me solve this. Deeply appreciate it!

Below is the script I've coded:

#Import the SCCM module
Import-Module "D:\APPS\SCCM\AdminConsole\bin\ConfigurationManager.psd1" 

#Get the input DP group name
$dpGroupName = Read-Host "Enter the DP group name"

#Get the list of all DPs in the specified DP group
$dps = Get-CMDistributionPoint | Where-Object {$_.DistributionPointGroup -eq $dpGroupName}

#Create an empty array to store the unique package IDs
$uniquePackageIds = @()

#Iterate through the list of DPs
foreach ($dp in $dps) {

#Get the WMI object for the DP
    $wmiObject = Get-WmiObject -Class SMS_DistributionPoint -ComputerName $dp.Name

#Get the list of packages distributed to the DP
    $packages = $wmiObject.PackageID

#Iterate through the list of packages
    foreach ($package in $packages) {

#Add the package ID to the array of unique package IDs
        $uniquePackageIds += $package
    }
}

#Create a CSV file
$csvFile = "C:\Users\GL-OPS-EU093\Desktop\Identify.csv"
$csvWriter = New-Object -Type System.IO.StreamWriter -ArgumentList $csvFile

#Write the unique package IDs to the CSV file
foreach ($packageId in $uniquePackageIds) {
            $csvWriter.WriteLine($packageId)
}

#Close the CSV file
$csvWriter.Close()
0

There are 0 answers