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.

Share

Updated: Import Computer Form v0.8 – Directly adding a User Device Affinity in ConfigMgr 2012

A few months ago I released the first public version of my Import Computer Form. I’ve had some nice feedback about it and also some good ideas for added functionality. This update will mainly be about three things:

  • Cleaning-up old code, by merging a few lines and adjusting some queries.
  • Adding error catching, by introducing an error provider for faulty input.
  • Adding functionality, by introducing an option to add a User Device Affinity/ Primary User.

Overview

These additions mean that this version gives the user the possibility to perform the following actions, without the need of access to and/ or a locally installed ConfigMgr console:

  • ImpoCompInfov08Fill in a Computer name.
  • Fill in a MAC Address.
  • Select an OS Deployment Collection.
  • Select a Primary User.
  • Import the Computer Information.
  • Add the User Device Affinity/ Primary User.
  • Close the form.

Inside information

CreaRelaWMII thought it might be nice to give some information about how easy it actually is to add this new functionality of adding a User Device Affinity/ Primary User. First start with looking for the class and the methods that hides the functionality that is needed. This can be done by, either browsing through WMI, or searching through the online reference on MSDN. As the screenshot shows, I like to use WMI Explorer. It also show that browsing to the class SMS_UserMachineRelationship reveals the method CreateRelationship, which again reveals its four parameters. For the exact information about the parameters it’s still necessary to look at MSDN. The “fun” part is that the input, of the parameters, is required in the order as shown in WMI. The order shown at the different MSDN articles is NOT the order needed as the input! After all the input is collected, the command line is “just” adding it all together in one Invoke-WmiMetod command, like this:

Invoke-WmiMethod -Namespace root/SMS/site_$($SiteCode) -Class SMS_UserMachineRelationship -Name CreateRelationship -ArgumentList @($ResourceID, 2, 1, $UserName) -ComputerName $SiteServer

Note: I used exactly the same way to change my method, for importing a machine, into a “one-liner”. This made it to an Invoke-WmiMethod for the class SMS_Site and the method ImportMachineEntry, like this:

Invoke-WmiMethod -Namespace root/SMS/site_$($SiteCode) -Class SMS_Site -Name ImportMachineEntry -ArgumentList @($null, $null, $null, $null, $null, $null, $MACAddress, $null, $ResourceName, $True, $null, $null) -ComputerName $SiteServer

Availability

As of today this updated version of my Import Computer Form is publicly available via the TechNet Galleries. Please let me know what you think of the tool.

>> Available via download here on the TechNet Galleries! <<

Share

Just Released: Import Computer Form v0.7

Today I released a public version of my Import Computer Form. Many has been written about scripts to Import Computer Information in ConfigMgr 2012, via PowerShell, but there was never a worked-out example (like all the different HTA’s there where for the previous version). That’s why I thought it would be nice to post an example form to just simply Import Computer Information in ConfigMgr 2012. Again, like with my Approval Manager, I did NOT use the PowerShell Cmdlets for ConfigMgr 2012, but just PowerShell to WMI. The main reason for that is, still the same, that using WMI, via PowerShell, is much friendlier for remote usage.

Import Computer Form

This public version gives the user the possibility to perform the following actions, without the need of access to and/ or a locally installed ConfigMgr console:

  • ImpoCompForm07Fill in a Computer name.
  • Fill in a MAC Address.
  • Select an OS Deployment Collection.
  • Import the Computer Information.
  • Close the form.

Security Role

This time I won’t spent to much time on specifying which rights are necessary to Import Computer Information. The reason for that is simple, as it’s been very good explained in this post on the TechNet Blogs

Public Available

As of today my Import Computer Form is publicly available via the TechNet Galleries. Please let me know what you think of the tool.

Share