SCCM Package Distribution Monitor

If you’ve installed the ConfigMgr 2012 R2 Toolkit, you’ve probably used the handy “Distribution Point Job Queue Manager” to monitor your distributions.  But you can also monitor them with Powershell if you wish to.  Here’s a simple script that will do just that.  It will identify the package ID, name and type, the distribution points that are currently receiving the distribution, when the distribution started, the total size of the package, the remaining size to be distributed, and overall progress of each individual distribution.

Note that ConfigMgr does some post-processing before the actual distribution is started, so if you try to monitor a distribution immediately after you distributed it, you might see no results.  One way to check when it’s started is to search for ‘Created package transfer job to send package … to distribution point’ in the distmgr.log on the site server.  Thinking about it, that could probably be scripted too, but that’s for another day 🙂

dp


## Variables ##
#!!Enter the sitecode here!!
$SiteCode = "ABC"

## Start of script

Import-Module 'C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1'
$Drive = $SiteCode + ':'
cd $Drive

cls
$Djobs = Get-WmiObject -Namespace root\SMS\Site_$SiteCode -Class SMS_DistributionJob | Select PkgID,NALPath,StartTime,RemainingSize,TotalSize

if ($djobs -eq $Null)
{
Write-host "There are no active distributions!" -ForegroundColor Yellow
Write-host "If you just distributed something, try again in a couple of minutes as the server may be processing the request."
write-host "Press any key"
$HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | OUT-NULL
$HOST.UI.RawUI.Flushinputbuffer()
exit
}

foreach ($Djob in $Djobs)
{
$ID = $djob.PkgID
# Get PackageName and Type

$PKG = Get-WmiObject -Namespace root\SMS\Site_$SiteCode -Class SMS_Package -Filter "PackageID='$ID'" | Select Name
If ($PKG -ne $null)
{
$Name = $PKG.Name
$Type = "Standard Package"
}

$BIPKG = Get-WmiObject -Namespace root\SMS\Site_$SiteCode -Class SMS_BootImagePackage -Filter "PackageID='$ID'" | Select Name
If ($BIPKG -ne $null)
{
$Name = $BIPKG.Name
$Type = "Boot Image Package"
}

$CNPKG = Get-WmiObject -Namespace root\SMS\Site_$SiteCode -Class SMS_ContentPackage -Filter "PackageID='$ID'" | Select Name
If ($CNPKG -ne $null)
{
$Name = $CNPKG.Name
$Type = "Application Content Package"
}

$DRVPKG = Get-WmiObject -Namespace root\SMS\Site_$SiteCode -Class SMS_DriverPackage -Filter "PackageID='$ID'" | Select Name
If ($DRVPKG -ne $null)
{
$Name = $DRVPKG.Name
$Type = "Driver Package"
}

$IMGPKG = Get-WmiObject -Namespace root\SMS\Site_$SiteCode -Class SMS_ImagePackage -Filter "PackageID='$ID'" | Select Name
If ($IMGPKG -ne $null)
{
$Name = $IMGPKG.Name
$Type = "Image Package"
}

$PkgID = $Djob.PkgID
$NALPath = $Djob.NALPath
if ($Djob.StartTime -ne $null)
{
$StartTime = [System.Management.ManagementDateTimeConverter]::ToDateTime($Djob.StartTime).DateTime
}
$RemainingSize = $Djob.RemainingSize
$TotalSize = $Djob.TotalSize
if ($RemainingSize -ne $Null)
{
$percentComplete = "{0:N0}" -f (100-$RemainingSize/$TotalSize*100) + " %"
}
Else
{
$percentComplete = "Not calculated yet"
}
$RemainingSize = "{0:N0}" -f ($RemainingSize / 1MB) + " MB"
$TotalSize = "{0:N0}" -f ($TotalSize / 1MB) + " MB"

write-host ""
write-host "Package Name: $Name" -ForegroundColor Cyan
write-host "Packge Type: $Type"
Write-host "Package ID: $PkgID"
Write-host "Distribution Point: $NALPath"
Write-host "Start Time: $StartTime"
write-host "Remaining Size: $RemainingSize"
write-host "Total Size: $TotalSize"
Write-host "Percent Complete: $percentComplete"
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s