TechEd Australia 2013 – PowerShell for ConfigMgr 2012 SP1 – Demo 3

 Demo 3: Collections

Creating a single Collection

New-CMDeviceCollection -LimitingCollectionName “All Systems” -Name “All Computers in 10.10.10.0” -RefreshType ConstantUpdate

Creating a Collection Query Membership Rule for the above Collection

Add-CMDeviceCollectionQueryMembershipRule -CollectionName “All Computers in 10.10.10.0” -QueryExpression “Select * from SMS_R_System where SMS_R_System.IPSubnets like ‘10.10.10.0’” -RuleName “10.10.10.0 Subnet Query”

Source CSV file automated Collection creation

NewMelbourneDCSubnets.csv (rename the file to NewMelbourneDCSubnets.csv)

Script creating Collections based on CSV file

$CSVSubnets = Import-Csv -Path .\NewMelbourneDCSubnets.csv
Set-Location PRI:\
ForEach($Collection in $CSVSubnets)
{
New-CMDeviceCollection -LimitingCollectionName “All Systems” -Name $Collection.SubnetName -RefreshType Constantupdate
Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection.SubnetName -QueryExpression “Select * from SMS_R_System where SMS_R_System.IPSubnets like ‘$($Collection.Subnet)'” -RuleName “$($Collection.Subnet) Subnet Query”
}