Kaido Jarvemets - Logo

Maximizing Efficiency with Configuration Manager Automation: Creating Device Collections Based on Device Model

As a Configuration Manager expert, I understand the importance of automation in streamlining processes and increasing efficiency within your organization. The use of automation can greatly reduce the time and effort spent on manual tasks, freeing up valuable resources for other projects.

One example of automation within Configuration Manager is the creation of Device Collections based on the device model. This allows you to easily organize and manage your devices based on specific criteria, such as the hardware model.

Create Device Collections for Lenovo Models

				
					<#
    =================================================================================
    DISCLAIMER:
    This script is provided "as-is" with no warranties. Usage of this script is at
    your own risk. The author is not liable for any damages or losses arising from
    using this script. Please review the full legal disclaimer at:
    https://kaidojarvemets.com/legal-disclaimer/
    =================================================================================
#>
#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
}
				
			

Create Device Collections for HP, Dell, etc

				
					<#
    =================================================================================
    DISCLAIMER:
    This script is provided "as-is" with no warranties. Usage of this script is at
    your own risk. The author is not liable for any damages or losses arising from
    using this script. Please review the full legal disclaimer at:
    https://kaidojarvemets.com/legal-disclaimer/
    =================================================================================
#>
#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
}
				
			

Leave a Reply

Contact me

If you’re interested in learning about Maximizing Efficiency with Configuration Manager Automation: Creating Device Collections Based on Device Model. I can help you understand how this solution can benefit your organization and provide a customized solution tailored to your specific needs.

Table of Contents