#Powershell script to create incremental collections based on CSV file and add AD Security Group (workstations) rule

#Import the module Import-module ‘D:\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1’

#Set Site to talk to Set-Location CM1:\

#CSV File to run and import $CSVfile = Import-Csv -Path “C:\Users\Sccm\Desktop\Scripty Script\collections_sccm.csv”

#For Each User Object Do This ForEach($Collection in $CSVfile) { New-CMUserCollection -LimitingCollectionName “All Users” -Name $Collection.collectionname -RefreshType Periodic Add-CMUserCollectionQueryMembershipRule -CollectionName $Collection.collectionname -QueryExpression “select SMS_R_USER.ResourceID,SMS_R_USER.ResourceType,SMS_R_USER.Name,SMS_R_USER.UniqueUserName,SMS_R_USER.WindowsNTDomain from SMS_R_User where SMS_R_User.SecurityGroupName like ‘DOMAINNAME\\$($Collection.groupname)’ “ -RuleName “$($Collection.groupname) AD Group Query” }

<#

Device Collection #For each object do this ForEach($Collection in $CSVfile) { New-CMDeviceCollection -LimitingCollectionName “All Users” -Name $Collection.collectionname -RefreshType Periodic Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection.collectionname -QueryExpression “select * from SMS_R_System where SMS_R_System.SystemGroupName = ‘DOMAINNAME\\$($Collection.groupname)’ “-RuleName “$($Collection.groupname) AD Group Query” }

#>