Imagine a scenario where you have a mass deployment collection with thousands of clients added to the collection using direct membership, and now you’ve been asked to remove one of the clients membership from that collection. You could always use the console, and try to find the one client in thousands, or you use something very basic as the PS script below to perform the same very task without going through console.

$collectionName = “Test”
$clientName = “Machine1”
$QueryClient = Get-CMDeviceCollectionDirectMembershipRule -CollectionName $CollectionName | Where-Object {$_.RuleName -eq $clients}
if ($QueryClient -ne $null)
{
$ResourceID = $QueryClient.ResourceID
Remove-CMDeviceCollectionDirectMembershipRule -CollectionName $CollectionName -ResourceId $ResourceID -Force:$true
Write-Host “Successfully removed client $clientName from the collection $collectionName” -ForegroundColor Green

}