Trigger Package Refresh via Powershell without SCCM Cmdlets

Question: How can I trigger the “Update Distribution Points” in the console via Powershell?


For packages:
(Get-WmiObject  -ComputerName
server -Namespace “root\sms\site_000” -query “select * from sms_package where packageID = ‘000005d6′”).RefreshPkgSource()

For applications:
(Get-WmiObject -ComputerName server -Namespace “root\sms\site_000” -query “select * from sms_contentpackage where SecurityKey = ‘ScopeId_B85B2C5F-F9F2-4EAB-BB71-3D8B2E8AEBDD/Application_55037dce-bdd6-4dcf-8959-58e96e9cb8cd'”).RefreshPkgSource()

Figure 1 – Console

All I could find online were articles on how to redistribute content to a specific site, not to refresh the source files, or articles using the SCCM Powershell cmdlets – but we wanted the flexibility to be able to run this script on any machine without needing those cmdlets. So here it goes. I opened up WBEMTEST, and queried all of the classes, and started scrolling through, until I found one called “SMS_Package”. I needed to rev a package, so naturally the class called SMS_Package drew my attention.

Figure 2: WBEMTEST

Now that we have a WMI class to explore, we can pipe it to a Get-Member to view all of the properties and methods.

Get-WmiObject -ComputerName server -namespace “root\sms\site_000” -class sms_package | Get-Member

The method that stuck out to me was RefreshPkgSource(), and a quick google search of “refreshpkgsource sms_package” led me to Microsoft to confirm that this method is safe to use.

Figure 3: SMS_Package WMI Class Properties and Methods

Once I had a WMI class, and a method, I queried the class with my package ID, to verify the source version.

Get-WmiObject -ComputerName server -namespace “root\sms\site_000” -query “select * from sms_package where packageid = ‘000005D6′” | select name, sourceversion

Figure 4: Querying WMI Class for Package

All together now…

(Get-WmiObject  -ComputerName server -Namespace “root\sms\site_000” -query “select * from sms_package where packageID = ‘000005d6′”).RefreshPkgSource()

Figure 5: Trigger refreshpkgsource()

If we open up the console and navigate to the monitoring node, we can see that the package is now redistributing to all sites.

Figure 6: Monitoring Node of Package in Console

And if we query the SMS_Package class again, the source version has now increased to sourceversion 6.

Figure 7: New source version in WMI

And that’s how you trigger a “Update distribution points” from powershell. But what if you want to update an application?

Trigger Refresh for Applications

Use WMI class SMS_ContentPackage and the security Key. You can copy the CI Unique ID from the console, but truncate the last two characters off of it, as it refers to the revision.

CI Unique ID: ScopeId_B85B2C5F-F9F2-4EAB-BB71-3D8B2E8AEBDD/Application_0b51dae2-480e-40eb-92a4-68a33f298f23/1

Security Key: ScopeId_B85B2C5F-F9F2-4EAB-BB71-3D8B2E8AEBDD/Application_0b51dae2-480e-40eb-92a4-68a33f298f23

(Get-WmiObject -ComputerName server -Namespace “root\sms\site_000” -query “select * from sms_contentpackage where SecurityKey = ‘ScopeId_B85B2C5F-F9F2-4EAB-BB71-3D8B2E8AEBDD/Application_55037dce-bdd6-4dcf-8959-58e96e9cb8cd'”).RefreshPkgSource()


Post navigation