Flanked by armored vehicles and a coterie of senior military officers, President Trump made an Independence Day pitch at the Lincoln Memorial: Join the U.S. military.

It was an unexpected turn in the “Salute to America,” an event he envisioned and planned. Steeped in military history and appreciation, the address lauded specific achievements in each service’s past, acknowledged the presence of Medal of Honor recipients in the crowd and urged youths to serve in uniform in the future.

“They and thousands before us served with immense distinction, and they loved every minute of that service,” Trump said of the veterans decorated for valor. “To young Americans across our country, now is your chance to join our military and make a truly great statement in life. And you should do it.”

The remark garnered some cheers from the crowd gathered before him. But it also hit on a reality for the Pentagon: Military officials are increasingly concerned about finding recruits. The challenges include increasing obesity across the nation, a growing economy that has provided other job opportunities and an overall declining desire among young Americans to serve.

Enter Trump. While the size, scope and multimillion-dollar cost of his Fourth of July extravaganza proved controversial, it also put the military front and center. The Pentagon spent weeks fending off questions about the president’s wish to have a full air show and tanks parked in Washington, but it also will likely benefit from the exposure.

In a Defense Department that spends million of dollars each year to advertise for recruits, military officials quietly carried out the White House’s directives for the event, setting aside flight hours designated for training to fly aircraft in the Salute, two defense officials said, speaking on the condition of anonymity because of the sensitivity of the issue.

It isn’t uncommon for the Pentagon to do the same for a flyover at an event like the Super Bowl, but this was unique in that it effectively included seven flyovers — one for each of the five military services, plus Air Force One leading off the evening and the Blue Angels closing the event. It also included aircraft that are rarely seen, including the B-2 stealth bomber and the Marine Corps’ new VH-92 presidential helicopter.

For months, the Pentagon was mum about how large its involvement on Independence Day would be — a symptom, defense officials said, of the president’s desire to inject showmanship and spring surprises on observers. That largely held up, until some officials began disclosing details to the media out of concern that it looked like the Pentagon was not prepared to meet Trump’s whims and was scrambling to keep up.

To be sure, Trump is not a perfect messenger for the military.

The president, who avoided military service in Vietnam through five deferments, has made inflammatory statements that have divided veterans, including verbally attacking the parents of Army Capt. Humayun Khan, a U.S. soldier who was killed in Iraq. He also said he did not think the late senator John McCain (R-Ariz.) was a war hero because “I like people who weren’t captured.” McCain, who suffered in captivity in North Vietnam for more than five years and died last year, received a Silver Star for valor.

Trump also has a history of making partisan attacks in front of active-duty service members, a habit that critics see as overtly politicizing the military.

Last month, the Pentagon directed the White House’s military office not to politicize events involving the military after an uproar that was created by a White House staff member directing Navy personnel in Japan to obscure the USS John S. McCain, a ship named after three generations of McCains, ahead of a presidential visit.

With Marine Gen. Joseph F. Dunford Jr., the chairman of the Joint Chiefs of Staff, and acting defense secretary Mark Esper alongside Trump on Thursday night, the Pentagon would have been put in a difficult position if the president had let loose with political attacks.

But Trump steered clear of doing so. Instead, he paid tribute to American heroes ranging from Frederick Douglass to Billy Mitchell, who is considered the father of the modern Air Force.

The president’s softer tone Thursday is unlikely to dissuade some detractors. Protesters could be found up and down the Mall, with balloons of “Baby Trump” — bearing the president’s likeness in a diaper — and signs decrying the militarization of Independence Day both common.

“It’s divisive,” said Stephen Samuels, a Washington resident who protested on Thursday afternoon along with his wife, Joanna Pratt. “He’s turned it into a political event, and it never has been before.”

But the event had a smaller military presence on the ground than the military parade Trump originally envisioned. It also managed to capture the attention of thousands of people in person, and even more on television.

For the Pentagon, it likely resulted in a best possible outcome.