There are some good ideas in Peter's answer, but I notice that they all imply or at least come from the perspective of the student being the actor. In many cases, this is just fine. In some other cases, the students may need more of a push, or may need to have some obstacles removed.
It has been reported that teachers themselves may try to steer students away from, among other things, advanced courses when they suspect a poor fit. According to a 2009 article by noted education journalist Jay Mathews,
A recent Fordham Institute survey revealed that only 38 percent of AP teachers believe "the more students taking AP courses, the better," while 52 percent said "only students who can handle the material" should take AP. One of my favorite bloggers, Fairfax County instructional technology specialist Tim Stahmer of assortedstuff.com, frequently says too many unprepared students are being channeled into AP and urged to go to college.
However, the rest of the article points out that even when supposedly unprepared students are given access to advanced courses, they have overall better outcomes. In many high schools, computer science is still seen as an advanced elective, similar to the AP courses described above. Even if the goal is not college prep, there is value in providing some exposure to another field, particularly CS.
Getting more students into classes may benefit from getting faculty and administration buy-in. This is obviously especially true if teachers, guidance counselors or principals are initially discouraging/blocking some students from taking CS courses, but even if that's not happening, some active encouragement can only help.
The title of the question also mentions diversity. "Diversity" is a broad term, but given the context of this site (and to simplify research) I'm assuming for the purposes of this question that you mean racial and gender diversity.
Research on diversity and education covers a lot of ground, but speaking broadly and relatively, it shows that (at least in the USA) minority students are treated worse. A few random examples:
The above is relevant because, where it is taking place, school staff may not even realize that their actions are reducing CS diversity. In other words, it is unconscious bias. Eliminating "gatekeepers" and having "suggest that all students register" policies can help with this.