The code in this post is to create the “All Windows 8.1 Clients” device collection in Chapter 5 of “Learn ConfigMgr 2012 in a Month of Lunches”
The collection is a standard Device Collection with a scheduled query as well as dynamic updates, and is populated using a WQL-based query.