WASHINGTON (AP) — It took seven months, but President Donald Trump finally has a Senate-confirmed secretary of defense.

Mark Esper, an Army veteran and former defense industry lobbyist, won Senate confirmation Tuesday by a vote of 90-8. He was to be officially sworn in by the end of the day, ending the longest period the Pentagon has gone without a confirmed leader in its history.

The turmoil atop the Pentagon began when Trump's first defense secretary, Jim Mattis, stepped down last New Year's Eve after a series of policy disputes with Trump. He offered to stay another two months to get a successor in place, but Trump said no.

Even with Esper now in charge, the problem of leadership instability at the Pentagon is not fully resolved. There still is no Senate-confirmed deputy secretary of defense, although David Norquist on Tuesday was nominated for the post and is scheduled to have a confirmation hearing Wednesday.

The senior leadership vacancies increased again last week with the departure of David Trachtenberg, the Pentagon's second-ranking civilian policy official.

Beyond that, the No. 2-ranking military officer, Gen. Paul Selva, is retiring Friday as vice chairman of the Joint Chiefs of Staff. No Senate confirmation hearing has been set for the man picked by Trump to replace Selva: Gen. John Hyten, who has been commander of U.S. nuclear forces as head of U.S. Strategic Command.

A military officer has accused Hyten of sexual misconduct . An investigation found insufficient evidence to charge Hyten, but some members of Congress have raised questions about that process. It's unclear when or whether Hyten's nomination will proceed.

At his confirmation hearing on July 16, Esper promised that one of his first priorities would be to fix the problem of leadership vacancies.

"I need to staff up the top tier of the Pentagon soonest," he said.

Carl Tobias, a professor of law at the University of Richmond, said he believes that in the months since Mattis left, the Pentagon's sway within the administration has weakened.

"This seems to be the primary challenge that Esper confronts: regaining the power to set the Defense Department agenda and defend it by doing what is best for the nation and the world, not what advances the president's political agenda," Tobias said by email.

Esper had been the Army secretary when Mattis resigned in December. On Jan. 1, the deputy defense secretary, Patrick Shanahan, became the acting secretary. But after nearly six months as the fill-in, the former Boeing executive abruptly quit .

Esper then became the acting defense secretary, but once he was nominated last week he had to step aside until after a Senate vote. So, for the past week the Pentagon had been run by yet another fill-in: Navy Secretary Richard V. Spencer.

Esper, who has a wide range of experience in defense matters, including time on Capitol Hill as a congressional staff member, has said he intends to continue the Trump administration's focus on improving the combat preparedness of the military, nurturing security alliances around the world and reforming Pentagon business practices.

All eight senators who voted against Esper's nomination are Democrats. They include Sen. Elizabeth Warren of Massachusetts, a candidate for the Democratic presidential nomination, who has sharply criticized Esper for declining to recuse himself from all matters involving his former employer, Raytheon Co., for the duration of his time as defense secretary.

Esper was a lobbyist for Raytheon, a major defense contractor, for several years before becoming Army secretary. He told Warren that Defense Department ethics officials recommended he not make the recusal commitment she asked about, but he pledged to abide by all ethics rules and regulations.