By The Associated Press and Tim Fitzsimons

In a rebuke to President Donald Trump, the House on Thursday voted against his administration's move to restrict transgender men and women from military service.

The nonbinding resolution passed 238-185, with every Democrat supporting it and almost every Republican voting against it.

The Trump administration's policy bars people who have undergone gender transition from enlisting. It also requires military personnel to serve as their biological gender unless they began a gender transition under less restrictive Obama administration rules.

The policy is being challenged in court.

“It’s a welcoming reassurance that the elected leaders in the U.S. House support the more than 13,000 brave transgender service members who proudly dedicate their lives to our nation,” said Sarah Kate Ellis, president and CEO of GLAAD, an LGBTQ advocacy organization. “It's time for President Trump to drop his proposed ban and stand with transgender patriots putting their lives on the line to keep us all safe.”

Rep. Joe Kennedy, D-Mass., and the resolution's sponsor, says Trump's policy amounts to "targeted discrimination." He says the House vote sends a message to transgender people "that they cannot be banned from military service because of who they are."

Only last month, a bipartisan group of legislators attempted to undo Trump's ban, which was announced in July 2017 in a series of tweets. Sens. Kirsten Gillibrand, D-N.Y., Jack Reed, D-R.I., and Susan Collins, R-Maine, introduced legislation in February that would permit transgender service members to continue to serve and allow trans people to join the military.

“The military wants and needs transgender service members, but this president is ready to put his own prejudice ahead of science and military readiness," Mara Keisling, executive director of the National Center for Transgender Equality, said. "It is more important than ever for Congress to stand up for troops and reject this flagrantly dangerous policy."

“Today’s bipartisan majority in the U.S. House join leading medical associations, national security experts and former military officials in opposing this dangerous and discriminatory policy," Sarah McBride, national press secretary for the Human Rights Campaign, said. "We urge the U.S. Senate to take action so that every service member can know that both the chambers of Congress respect their service.”