-
-
Save Kaidja/18b54639d52619081cc3fa63c0df74e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 Vendor,Version from SMS_G_System_COMPUTER_SYSTEM_PRODUCT where Vendor = 'Lenovo'" | |
$LimitingCollectionName = 'All Systems' | |
$LenovoModels = Get-CimInstance -Namespace "Root\SMS\Site_$($SiteCode.Name)" -Query $Query | Select-Object -Property Vendor,Version -Unique | |
foreach($Model in $LenovoModels){ | |
Write-Output -InputObject "Create - All Lenovo $($Model.Version) - Collection" | |
$CollectionName = "All Lenovo $($Model.Version)" | |
$LenovoQuery = "select * from SMS_R_System inner join SMS_G_System_COMPUTER_SYSTEM_PRODUCT on SMS_G_System_COMPUTER_SYSTEM_PRODUCT.ResourceId = SMS_R_System.ResourceId where SMS_G_System_COMPUTER_SYSTEM_PRODUCT.Version = '$($Model.Version)'" | |
New-CMCollection -CollectionType Device -Name $CollectionName -LimitingCollectionName $LimitingCollectionName | | |
Move-CMObject -FolderPath $CollectionFolderRoot | |
Add-CMDeviceCollectionQueryMembershipRule -CollectionName $CollectionName -RuleName $CollectionName -QueryExpression $LenovoQuery | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment