NEW YORK — Harvey Weinstein’s bail was increased from $1 million to $5 million on Wednesday over allegations he violated bail conditions by mishandling his electronic ankle monitor.

But Weinstein's defense team chose an option that lets him meet his bail obligation by putting up $2 million through a bail bondsman, and Judge James Burke rejected prosecution calls to put the disgraced movie mogul in jail over the alleged violation.

Weinstein, 67, arrived at court in the morning using a walker, and his lawyer said he will be undergoing back surgery on Thursday. In his last court appearance, he also struggled to walk. Burke warned that he would revoke his bail and issue a warrant for his arrest if other issues crop up.

“If you have any further medical issues, the court will not be terribly understanding,” Burke said.

Weinstein was calm and respectful during the hearing and indicated that the surgery would help ensure his appearance at his trial. The disgraced movie mogul is scheduled to stand trial in New York City beginning Jan. 6 on rape and sexual assault charges.

“As it was made clear in court today, Mr. Weinstein is looking forward to Jan. 6,“ said Weinstein's lawyer, Donna Rotunno.

Prosecutor Joan Illuzzi said at a hearing Friday that Weinstein has repeatedly, purposely left at home a piece of the monitoring technology that keeps the ankle bracelet activated.

That has left his whereabouts unrecorded for hours at a time, she said.

Rotunno has denied it was anything deliberate, blaming “technical glitches” like dead batteries and said it had nothing to do with manipulation of the bracelet, though she acknowledged that on at least one occasion, he’d forgotten part of the device at house.

But on Wednesday, Illuzzi told the court that the person monitoring Weinstein does not believe the problems due to were technical glitches. While the monitoring now appears to be working, Illuzzi said she thought that was because of the threat of new bail.

“I don't think it was the adding of the extra batteries,” Illuzzi said. “It was Mr. Weinstein’s panic that the court might change the bail.”

Weinstein has pleaded not guilty to charges he raped a woman in a Manhattan hotel room in 2013 and performed a forcible sex act on a different woman in 2006.

He has been free on the current $1 million bail and maintains that any sexual activity was consensual.

In recent months, Weinstein has been spotted hobnobbing at New York City nightclubs and getting jeered at a recent actors showcase.

lluzzi argued that it wouldn’t be unreasonable to put Weinstein in jail pending trial. If the judge doesn’t think jail is warranted, the prosecutor suggested Weinstein’s bail be raised from $1 million to $5 million.

Judge James Burke put off a decision until Wednesday’s hearing.

Weinstein hobbled into last week’s hearing and looked more pained than usual. His lawyer told reporters that he’s dealing with back issues.