Remove Single Client from the SCCM collection using Powershell

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

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s