PowerShell Script to check active package distributions
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 rootsms SMS_ProviderLocation -filter "ProviderForLocalSite='True'"
$sitecode = $providerLocation.SiteCode
$providerNamespace = "rootsmssite_" + $sitecode
###################################################
Updated script below
)
####################################################################################################################################
##Check the content distribution queue on a primary
$providerLocation = gcim -ComputerName $siteServerName -Namespace rootsms SMS_ProviderLocation -filter "ProviderForLocalSite='True'"
$sitecode = $providerLocation.SiteCode
$providerNamespace = "rootsmssite_" + $sitecode
$count = (Get-WmiObject -Namespace $providerNamespace -Class SMS_DistributionJob).count
$Activethreadcount = (Get-WmiObject -Namespace "rootSMSSite_$($SiteCode)" -Class SMS_DistributionJob | Where {$_.Starttime -ne $null}).Count
$Activethreads = Get-WmiObject -Namespace "rootSMSSite_$($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
https://msdn.microsoft.com/en-us/library/hh948405.aspx
Comments
- Anonymous
December 04, 2014
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 "rootSMSSite_$($SiteCode)" -ComputerName $siteServerNameRunning
Running on Windows 2012r2 with powershell v4.