Configuration Manager 2012 Create Collection OS Structure with PowerShell

For creating Operating System Collections create a “CreateCollection.ps1” file and paste the PowerShell code below in the file (or download the file below). If needed change the variables $CMSiteCode and $CMModule in the script.

This will create the following structur.

Configuration Manager 2012 Create Collection OS Structure with PowerShell

# Variables
$PWDBegin=$PWD
$CMSiteCode=“P01” # Change this – This should be your site code
$CMModule=‘C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1’ # Change this – This should point to the CM module
Import-Module$CMModule
$CMSiteCode=$CMSiteCode+“:”
Set-Location$CMSiteCode
New-CMDeviceCollection-Name“Windows 8”-LimitingCollectionId“SMS00001”
Add-CMDeviceCollectionQueryMembershipRule-CollectionName“Windows 8”-QueryExpression“select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier, SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where sms_R_System.Operating_System_Name_and0 like ‘%Microsoft Windows NT Workstation 6.2%'”-RuleName“Windows 8”
New-CMDeviceCollection-Name“Windows 7”-LimitingCollectionId“SMS00001”
Add-CMDeviceCollectionQueryMembershipRule-CollectionName“Windows 7”-QueryExpression“select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier, SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where sms_R_System.Operating_System_Name_and0 like ‘%Microsoft Windows NT Workstation 6.1%'”-RuleName“Windows 7”
New-CMDeviceCollection-Name“Windows Vista”-LimitingCollectionId“SMS00001”
Add-CMDeviceCollectionQueryMembershipRule-CollectionName“Windows Vista”-QueryExpression“select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier, SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where sms_R_System.Operating_System_Name_and0 like ‘%Microsoft Windows NT Workstation 6.0%'”-RuleName“Windows Vista”
New-CMDeviceCollection-Name“Windows XP”-LimitingCollectionId“SMS00001”
Add-CMDeviceCollectionQueryMembershipRule-CollectionName“Windows XP”-QueryExpression“select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier, SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where sms_R_System.Operating_System_Name_and0 like ‘%Microsoft Windows NT Workstation 5.1%'”-RuleName“Windows XP”
New-CMDeviceCollection-Name“Windows Server 2012”-LimitingCollectionId“SMS00001”
Add-CMDeviceCollectionQueryMembershipRule-CollectionName“Windows Server 2012”-QueryExpression“select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier, SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where sms_R_System.Operating_System_Name_and0 like ‘%Microsoft Windows NT Server 6.2%'”-RuleName“Windows Server 2012”
New-CMDeviceCollection-Name“Windows Server 2008 R2”-LimitingCollectionId“SMS00001”
Add-CMDeviceCollectionQueryMembershipRule-CollectionName“Windows Server 2008 R2”-QueryExpression“select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier, SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where sms_R_System.Operating_System_Name_and0 like ‘%Microsoft Windows NT Server 6.1%'”-RuleName“Windows Server 2008 R2”
New-CMDeviceCollection-Name“Windows Server 2008”-LimitingCollectionId“SMS00001”
Add-CMDeviceCollectionQueryMembershipRule-CollectionName“Windows Server 2008”-QueryExpression“select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier, SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where sms_R_System.Operating_System_Name_and0 like ‘%Microsoft Windows NT Server 6.0%'”-RuleName“Windows Server 2008”
New-CMDeviceCollection-Name“Windows Server 2003”-LimitingCollectionId“SMS00001”
Add-CMDeviceCollectionQueryMembershipRule-CollectionName“Windows Server 2003”-QueryExpression“select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier, SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where sms_R_System.Operating_System_Name_and0 like ‘%Microsoft Windows NT Server 5.2%'”-RuleName“Windows Server 2003”
Set-Location$PWDBegin

Download the script: CreateCollections

No comments yet.

Leave a Reply