Acting defense secretary Patrick Shanahan toured the U.S. border with Mexico on Saturday as the Pentagon prepares to allocate billions of dollars toward the construction of President Trump’s border wall.

The visit marked the most visible foray to date by Shanahan, a former Boeing executive who became acting Pentagon chief last month, into the president’s politically charged immigration agenda.

It occurred as Shanahan examines a proposal to shift as much as $3.6 billion in planned military construction funding toward fortifying the border, a step made possible by Trump’s declaration of a national emergency related to a perceived threat from undocumented immigrants. The declaration has prompted legislative challenges from Democrats while threatening to divide Republicans whose states could lose out on coveted military projects.

Speaking to reporters after a several-hours visit, Shanahan said his conversations with officials from Customs and Border Protection (CBP) and observations at sites in Texas and New Mexico had underscored the role the military can play in helping detect and deter illegal migration while freeing up Border Patrol agents.

“DOD can really help,” Shanahan said, suggesting the Pentagon, based on its experience monitoring threats overseas, might assume a new ongoing role in advising domestic agencies as they seek to enhance surveillance and monitoring at the border. “I’m hoping we can bring a broader approach to solving some of these problems.”

While assistance at the southern border lies outside the traditional Pentagon mission, Shanahan said, the border mission “is a priority of the commander in chief” and was one in which the military could potentially address what he identified as “systematic flaws” in addressing illegal entry. “Let’s not do triage,” he said.

Such a mission would be a departure for an agency that has been periodically pulled into discreet border missions in recent years but has traditionally prioritized overseas engagements.

Like his predecessor Jim Mattis, the retired Marine general who abruptly resigned in December over differences with Trump, Shanahan, a relative newcomer to Washington politics, must tread a careful line between deferring to the president’s wishes and limiting the Pentagon’s involvement in a mission that critics say detracts from Pentagon priorities including counterterrorism and China.

Shanahan, who spent 18 months in the Pentagon’s ­lower-profile No. 2 role, must also demonstrate his deft handling of this fraught and intensely scrutinized issue at a moment when the president is considering nominating him to remain in the job.

During his visit, Shanahan met with CBP and military officials and flew over rural areas where high border fencing may be built.

At one nearby border point overlooking the New Mexico-Mexico line, CBP officials showcased tools they use to patrol against illegal crossings and drug trafficking, including horses, all-terrain vehicles, long-range cameras and “less lethal” weapons that fire pepper balls.

In Texas, Shanahan was joined by Gen. Joseph F. Dunford Jr., chairman of the Joint Chiefs of Staff, who has overseen preparation of a preliminary assessment of how military construction funds could be repurposed for construction at the border.

As the Department of Homeland Security provides the Pentagon with a detailed request for military assistance in the funding of new or updated roads, fencing and lighting, Shanahan will have to determine how much military construction funding will be freed up for the work.

Officials said Shanahan could choose to put less than the maximum $3.6 billion from available military construction funds and would not cancel or delay projects that would impact military housing or affect readiness.

The Defense Department is also planning to allocate up to $2.5 billion for the border under a separate authority related to support for drug enforcement activities.

Repurposing military funds allows Trump to advance his desire to fortify the border despite Congress’s refusal to meet a larger White House request. But the declaration of a national emergency has triggered a host of lawsuits to prevent the president from moving forward.

On Friday officials said the Pentagon would add another 1,000 military personnel to the existing border mission, bringing the total including active duty and National Guard to 6,000.

While previous presidents have employed the National Guard for border fortification, Trump’s decision to send active-duty troops in the lead-up to the midterm elections last fall generated criticism the president was using the issue for political ends.