Tuesday, June 19, 2018

SCCM - Get Content Distribution Package Type - Powershell

Sometimes, you need to know what is Package Type (Package ? Application ? Driver ?) in "\Monitoring\Overview\Distribution Status\Content Status"



 
For that you  must use SMS_PackageBaseClass (Microsoft doc at SMS_PackageBaseClass) using PackageType property


Value  = Description = Type (in "Content Status")
0 = Regular software distribution package. = "Package"
3 = Driver package. = "Driver package"
4 = Task sequence package.
5 = Software update package. = "Software Update Package"
6 = Device setting package.
7 = Virtual application package.
8 = Application package. = "Application"
257 = Image package. = "Operating system Image"
258 = Boot image package. = "Boot Image"
259 = Operating system install package. =  "Operating System Upgrade Package"
260 = VHD package.

Value 4 "Task sequence package" corresponding to "\Software Library\Overview\Operating Systems\Task Sequences" (if you enable column "Package Type" you will see 4)















Below a powershell script example to export some Package information to "export_packages_info.csv" file. 



<#
.Synopsis
   Get All Package Type

.EXAMPLE
   .\Get-AllPackageType .ps1

.NOTES
  Version:        1.0
  Author:        Franck RICHARD
  Creation Date:    2018-06
  Purpose/Change:

#>
[cmdletbinding()]
Param(
     [String]$CM="myprimary.mydomain.net"
    ,[String]$PrimarySiteCode="XXX"
)


# *************************

# Get all packages
#
Write-Host "Get all Packages"
[HashTable] $hashPackageByPackageID = @{}
$arrSMS_PackageBaseclass = @(Get-WmiObject -Namespace "root\SMS\Site_$PrimarySiteCode" -Class SMS_PackageBaseclass -ComputerName $CM)
Foreach ($SMS_PackageBaseclass in $arrSMS_PackageBaseclass) {
    if ($hashPackageByPackageID.ContainsKey($SMS_PackageBaseclass.PackageID) ) {
        # Should not arrive problem in DB
    } else {
        $hashPackageByPackageID[$($SMS_PackageBaseclass.PackageID)] = $SMS_PackageBaseclass
    }
}

# *************************

# Write all package name and Package Type
#
$strContent = "PackageId;PackageTypeValue;ObjectPath;Name"  + "`r`n"

Foreach ($PackageID in $hashPackageByPackageID.Keys) {
    $SMS_PackageBaseclass = $hashPackageByPackageID[$PackageID]

    $PackageType = $SMS_PackageBaseclass.PackageType
    $Name = $SMS_PackageBaseclass.Name
    $ObjectPath = $SMS_PackageBaseclass.ObjectPath

            Switch ($PackageType) {
            0 {
                $PackageTypeValue = "Standard Package"
            }
            3 {
                $PackageTypeValue = "Driver Package"
            }
            4 {
                $PackageTypeValue = "Task Sequence Package"
            }
            5 {
                $PackageTypeValue = "Software Update Package"
            }
            6 {
                $PackageTypeValue = "Device Setting Package"
            }
            7 {
                $PackageTypeValue = "Virtual App Package"
            }
            8 {
                $PackageTypeValue = "Application Package"
            }
            257 {
                $PackageTypeValue = "Operating system Image Package"
            }
            258 {
                $PackageTypeValue = "Boot Image Package"
            }
            259 {
                $PackageTypeValue = "Operating System Upgrade Package"
            }
            260 {
                $PackageTypeValue = "VHD package"
            }
        } # switch end

    $strLine = $PackageID + ";" + $PackageTypeValue + ";" + $ObjectPath + ";" + $Name  + "`r`n"
    $strContent = $strContent + $strLine

}
Write-Host "Write export_packages_info.csv file with all package informations"
$strContent | Out-File -FilePath  "export_packages_info.csv"





If you just need Package Type information because you use  Remove-CMContentDistribution cmdlet  or another cmdlet "Package Type" dependent, better thing is to use an hashtable with only PackageType. Something like:
$hashPackageType[$($SMS_PackageBaseclass.PackageID)] = $($SMS_PackageBaseclass.PackageType)
Then when you have you PackageID to know your PackageType
$PackageType = $hashPackageType[$PackageID]




No comments: