Here is a script I cobbled together from various places that you can use to automate creating a user collection and AD group:
# Input Parameters
param([parameter(mandatory=$true, HelpMessage="Enter the collection name")] [string]$CollectionName, [parameter(mandatory=$true, HelpMessage="Enter a description of the collection")] [string]$Description, [parameter(mandatory=$true, HelpMessage="Enter user name to add")] [array]$UserNames)
# Set Variables
$SiteCode = "ABC"
$LimitingCollection = "All Users and User Groups"
$GroupOU = "OU=Applications, OU=Groups, OU=Test, DC=mydomain, DC=com"
$DomainName = 'MYDOMAIN'
$ADGrp="'"+$DomainName+'\\'+$CollectionName+"'"
$QueryExp='"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.UserGroupName='
# Installation path of console and ConfigMgr PowerShell module
$CMPowerShellPath = 'E:\Program Files\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1'
# Import AD and ConfigMgr modules
Import-Module ActiveDirectory
Import-Module $CMPowerShellPath
# Main Script Execution
# change to the CM Provider directory
cd ($SiteCode + ":")
$Schedule = New-CMSchedule RecurInterval Hours RecurCount 4
# Create AD group based on name provided
New-ADGroup -Name $CollectionName -SamAccountName $CollectionName -GroupCategory Security -GroupScope Global -DisplayName $CollectionName -Path $GroupOU
# Add users to new group
Foreach ($username in $usernames)
{
Add-ADGroupMember $CollectionName $UserName
}
# Create collection based on name provided
New-CMUserCollection -Name $CollectionName -LimitingCollectionName $LimitingCollection -Comment $description -RefreshType 'Periodic' -RefreshSchedule $Schedule
Add-CMUserCollectionQueryMembershipRule -CollectionName $CollectionName -QueryExpression $QueryExp$ADGrp -RuleName $CollectionName
Jeff