PowerShell Script to check active package distributions

PowerShell Script to check active package distributions

  • Comments 1
  • Likes

 

Hi All,

I had a need at a customer to write a script that would identify any active package distributions at a primary site via WMI. Although DPJobMgr will also give you more information and control this script returns a quicker result and in the case I was dealing with when you have a large number of active package distributions this can come in handy. Hopefully you'll find it useful.

The script is based on the SMS_DistributionJob Server WMI Class

 

(UPDATE. Matt just provided me with the following code that will give you your Primary site code automatically from WMI. thanks Matty.

##################################################

$providerLocation = gcim -ComputerName $siteServerName -Namespace root\sms SMS_ProviderLocation -filter "ProviderForLocalSite='True'"

$sitecode = $providerLocation.SiteCode

$providerNamespace = "root\sms\site_" + $sitecode

###################################################

Updated script below

)

####################################################################################################################################

##Check the content distribution queue on a primary

$providerLocation = gcim -ComputerName $siteServerName -Namespace root\sms SMS_ProviderLocation -filter "ProviderForLocalSite='True'"
$sitecode = $providerLocation.SiteCode
$providerNamespace = "root\sms\site_" + $sitecode

$count = (Get-WmiObject -Namespace $providerNamespace -Class SMS_DistributionJob).count

$Activethreadcount = (Get-WmiObject -Namespace "root\SMS\Site_$($SiteCode)" -Class SMS_DistributionJob | Where {$_.Starttime -ne $null}).Count

$Activethreads = Get-WmiObject -Namespace "root\SMS\Site_$($SiteCode)" -Class SMS_DistributionJob | Where {$_.Starttime -ne $null} | Format-List -Property Starttime, RemainingSize

Write-Output "Total Current Active Distributions $($count)"

Write-Output "Total Active Threads Count $($Activethreadcount)"

Write-Output "Current Threads" $Activethreads

####################################################################################################################################

Feel free to post any updates or even scripts that you've written in the comments below.

If you want to look at other classes that could provide you with more information just check out the following MSDN reference

http://msdn.microsoft.com/en-us/library/hh948405.aspx

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • It didn't work for me till I added -ComputerName $siteServerName after Get-WmiObject on the lines that didn't have it. eg

    Get-WmiObject -Namespace "root\SMS\Site_$($SiteCode)" -ComputerName $siteServerNameRunning

    Running on Windows 2012r2 with powershell v4.