Update Collection Membership in ConfigMgr 2012 via PowerShell

A few weeks ago I’ve got the question if it is possible to speed-up the collection membership update after a new device was added to the database via my Import Comport Form. The short answer is, of course, yes! As this answer would make a really short blog post, I decided to put some more time in it. My first answer could have been, why can’t you wait on the incremental update cycle. As by default, the Use incremental updates for this collection is selected (and grayed-out) for the All Systems collection and the default Interval for Collection Membership Evaluation is five minutes (see this post for more information).

Solution

Now what can we do when either five minutes takes to long, or the default interval is changed to something longer and we can’t allow access to the ConfigMgr Console and we also don’t want to get called all the time. The answer is, of course, PowerShell! In WMI there is the class SMS_Collection, which has the method RequestRefresh. This method triggers a re-evaluation of the collection memberships and doesn’t require any parameters. The best part is, this can be done with a one-liner! I like short and simple code. All we need is the path to the collection and that brings us to the following code:

Invoke-WmiMethod ` -Path "ROOT\SMS\Site_$($SiteCode):SMS_Collection.CollectionId='$CollectionId'" ` -Name RequestRefresh -ComputerName $SiteServer

Import Computer Form

Somewhere this week, I will post an updated version of my Import Computer Form. This update will include this one-liner to re-evaluate the collection memberships after the new device is added to the database. So whatever  configuration there may be, the collection will be directly updated.

3 thoughts on “Update Collection Membership in ConfigMgr 2012 via PowerShell”

  1. Hi Peter,

    the import computer form is a great solution for a simple task 😉
    About the collection update that will be triggerd:
    Can you trigger the update on the collection where the system is imported if i select a specified collection instead of all systems?

    Thanks
    Michael

    Reply
    • Hi Michael,
      There is no need for triggering an update on the collection, as I’m adding the device as a direct member. As soon as the device is available in the All Systems, it will be available in the limited collection.
      Peter

      Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.