I'm attempting to create a query using PowerShell to count the number of Lenovo ThinkPad devices with a specific IP range. Code derived from https://computergarage.org/how-to-create-sccm-device-collections-via-powershell.html
# Set Site Code
$SiteCode = Get-PSDrive -PSProvider CMSITE
Set-Location “$($SiteCode.Name):”
# Set Details
$DeviceCollectionName = "ThinkPads"
$FolderPath = “.\DeviceCollection\ThinkPads”
$Query = 'select * from SMS_R_System inner join SMS_G_System_NETWORK_ADAPTER_CONFIGURATION on SMS_G_System_NETWORK_ADAPTER_CONFIGURATION.ResourceId = SMS_R_System.ResourceId inner join SMS_G_System_COMPUTER_SYSTEM_PRODUCT on SMS_G_System_COMPUTER_SYSTEM_PRODUCT.ResourceId = SMS_R_System.ResourceId where SMS_G_System_NETWORK_ADAPTER_CONFIGURATION.IPAddress like
"10.1.%" and SMS_G_System_COMPUTER_SYSTEM_PRODUCT.Version like "%ThinkPad%"'
# Push Query
$NewCollection = Add-CMDeviceCollectionQueryMembershipRule -CollectionName $DeviceCollectionName -QueryExpression $Query -RuleName $DeviceCollectionName
Move-CMObject -FolderPath $FolderPath -InputObject $NewCollection
# Error
Add-CMDeviceCollectionQueryMembershipRule : No object corresponds to the specified parameters. At line:23 char:5
+ Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Device ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Confi...yMembershipRule:AddDeviceCollectionQueryMembershipRule) [Add-CMDeviceCol...yMembershipRule], ItemNotFoundException
+ FullyQualifiedErrorId : ItemNotFound,Microsoft.ConfigurationManagement.Cmdlets.Collections.Commands.AddDeviceCollectionQueryMembershipRule
Can someone explain what the error refers to? If I run the Add-CMDeviceCollectionQueryMembershipRule by itself, it requests all required info, then fails.