This is similar to your code, but I think you had the quoting wrong in the filter string. You only need to quote the value of you quote the filter string. If you use "curly braces" around the filter string you shouldn't quote the value.
I also removed and added the members in one execution of the Remove-ADGroupMember and Add-ADGroupMember cmdlet instead of individually.
Is "TEST" the samaccountname of the group? Or is it just the name of the group? It makes a difference.
$groupid = "TEST" # NOTE: This must be one of these:
# A distinguished name
# A GUID (objectGUID)
# A security identifier (objectSid)
# A Security Account Manager account name (sAMAccountName)
[array]$distnames = Get-ADGroupMember -Identity $groupid |
Get-ADUser -Properties msRTCSIP-Line |
Where-Object {$_.msRTCSIP-Line -eq $null} |
Select-Object -Expand distinguishedname
Remove-ADGroupMember -Identity $groupid -Members $distnames -Confirm:$false
[array]$adddistnames = Get-ADUser -SearchBase 'DC=company , DC=test' -filter {msRTCSIP-Line -ne $null}|
Select-Object -Expand distinguishedname
Add-ADGroupMember -Identity $groupid -Members $adddistnames