Skip to content

Instantly share code, notes, and snippets.

@Kaidja
Created June 21, 2018 18:33
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 Kaidja/f75f28d2590db1123081e757d2885fb1 to your computer and use it in GitHub Desktop.
Save Kaidja/f75f28d2590db1123081e757d2885fb1 to your computer and use it in GitHub Desktop.
#Import Module
Import-Module $env:SMS_ADMIN_UI_PATH.Replace("\bin\i386","\bin\configurationmanager.psd1")
$SiteCode = Get-PSDrive -PSProvider CMSITE
Set-Location "$($SiteCode.Name):\"
$CollectionFolderRoot = "$($SiteCode.Name):\DeviceCollection\Client Health\By Hardware Model"
$Query = "select Manufacturer,Model from SMS_G_System_COMPUTER_SYSTEM where Manufacturer <>'Lenovo'"
$LimitingCollectionName = 'All Systems'
$OtherModels = Get-CimInstance -Namespace "Root\SMS\Site_$($SiteCode.Name)" -Query $Query | Select-Object -Property Model,Manufacturer -Unique
foreach($Model in $OtherModels){
Write-Output -InputObject "Create - All $($Model.Manufacturer) $($Model.Model) - Collection"
$CollectionName = "All $($Model.Manufacturer) $($Model.Model)"
$HWQuery = "select * from SMS_R_System inner join SMS_G_System_COMPUTER_SYSTEM on SMS_G_System_COMPUTER_SYSTEM.ResourceId = SMS_R_System.ResourceId where SMS_G_System_COMPUTER_SYSTEM.Model = '$($Model.Model)'"
New-CMCollection -CollectionType Device -Name $CollectionName -LimitingCollectionName $LimitingCollectionName |
Move-CMObject -FolderPath $CollectionFolderRoot
Add-CMDeviceCollectionQueryMembershipRule -CollectionName $CollectionName -RuleName $CollectionName -QueryExpression $HWQuery
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment