#Create the required ‘global’ variables
$ConfigMgrModulePath=“[PATH TO CM]\ConfigurationManager.psd1”
$ConfigMgrSiteCode=“[SITE CODE]:”
#Connecting to site
Import-Module $ConfigMgrModulePath
Set-Location $ConfigMgrSiteCode
#Creating the User Collections
Import-CSV [PATH_TO\]BulkCreateUserCollections.csv | %{
#Create the required ‘local’ variables
$AllUsers="All Users"
$RefreshType="Periodic"
$RefreshSchedule=New-CMSchedule -RecurInterval Hours -RecurCount 1
$DomainName=“[DOMAIN]”
$UCInstallName="'"+$DomainName+'\\CM '+$_.CMName+"'"
# $UCUninstallName=“Uninstall “+$_.BulkCreateUserCollections
$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='
#Create the User Collection with a query rule
New-CMUserCollection -LimitingCollectionName $AllUsers -Name $_.CMName -RefreshType $RefreshType -RefreshSchedule $RefreshSchedule
$QueryExpression
$UCInstallName
Add-CMUserCollectionQueryMembershipRule -CollectionName $_.CMName -RuleName $_.CMName -QueryExpression $QueryExpression$UCInstallName
#Create the ‘uninstall’ User Collection with 2 rules: include All Users and exclude the User Collection
# New-CMUserCollection -LimitingCollectionName $AllUsers -Name $UCUninstallName -RefreshType $RefreshType
# Add-CMUserCollectionIncludeMembershipRule -CollectionName $UCUninstallName -IncludeCollectionName $AllUsers
# Add-CMUserCollectionExcludeMembershipRule -CollectionName $UCUninstallName -ExcludeCollectionName $_.BulkCreateUserCollections
}
No comments:
Post a Comment