I agree. However, your question asked CAN a church prevent an "undesirable" from attending. The answer is yes. If you ask SHOULD they, well then, that's another large economy-sized can of worms altogether.
Why does Christ want this to happen? Several reasons: (1) For the purity of His church; (2) to avoid charges of hypocrasy; (3) as a warning to believers; (4) as a means to (hopefully) correct the sin and restore the member to the church. There are other reasons, too, but that's the gyst of it.
A church that follow Biblical teaching WILL do this: it's not done often, and it is very difficult, but must be performed for all of the reasons discussed.
My church had to go through the pain of actually removing a pastor for displinary reasons. If we hadn't, the church likely would no longer exist. But we're still here and doing God's work.
So please, do not look on this as a harmful, hateful thing: it is much more along the lines of correcting the misbehavior of a child. You DON'T want to expel the child: you want to restore him/her to the family. The same thing goes here.