A judge on Wednesday granted Orange County a preliminary injunction that stops New York City from sending more migrants and homeless people to hotels in the county "until the city complies with state law regarding the exportation of its homeless," officials announced in a statement on the county website.

The decision was the first of its kind brought by a county against New York City, Orange County officials said.

County Executive Steven M. Neuhaus thanked County Attorney Rick Golden and staff for "achieving this successful result.”

“This issue needs to be resolved at the State and Federal levels," Neuhaus said in a statement. "They must come up with a better plan.”

State Supreme Court Judge Sandra Sciortino ruled New York City and Orange County hotels are enjoined from transporting or receiving homeless individuals without complying with state social services law and an order from the court, Orange County said.

"The only exception is the 186 individuals presently residing in two hotels in the County," including The Crossroads Hotel and the Ramada at Wyndham, both in the town of Newburgh, the statement says.

Under the ruling, the county can inspect the hotels housing the migrants, and are entitled to identification for all 186; New York City is responsible for expenses for all related services and may not end such payments after four months, according to the county.

The NYCLU said Wednesday afternoon that it was reviewing the decision.