Skip to content

Instantly share code, notes, and snippets.

@keithga
Created January 26, 2018 05:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keithga/96aafefaa36573efced69cd0d1d20eb4 to your computer and use it in GitHub Desktop.
Save keithga/96aafefaa36573efced69cd0d1d20eb4 to your computer and use it in GitHub Desktop.
Add-CMDeviceCollectionDirectMembership Slow
<#
Example of how to create a Device Collection and populate it with computer objects
The Slow way. <Yuck>
#>
[cmdletbinding()]
param(
$CollBaseName = 'MyTestCol_03_{0:D4}',
$name = 'PCTest*'
)
foreach ( $Count in 5,50 ) {
$CollName = $CollBaseName -f $Count
write-verbose "Create a collection called '$CollName'"
New-CMDeviceCollection -LimitingCollectionName 'All Systems' -Name $CollName | % name | write-Host
Measure-Command {
Write-Verbose "Find all Devices that match [$Name], grab only the first $Count, and add to Collection [$CollName]"
get-cmdevice -name $name -Fast |
Select-Object -first $count |
Foreach-Object {
Add-CMDeviceCollectionDirectMembershipRule -CollectionName $CollName -ResourceId $_.ResourceID -verbose:$False
}
} | % TotalSeconds | write-Host
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment