PHOENIX — The more than 5,200 active-duty troops being sent by President Donald Trump to the U.S.-Mexico border will be limited in what they can do under a federal law that restricts the military from engaging in law enforcement on American soil.

That means the troops will not be allowed to detain immigrants, seize drugs from smugglers or have any direct involvement in stopping a migrant caravan that is still about 1,000 miles from the nearest border crossing.

Their role will largely mirror that of the existing National Guard troops deployed to the border over the past six months.

Instead, their role will largely mirror that of the existing National Guard troops — about 2,000 in all — deployed to the border over the past six months, including providing helicopter support for border missions, installing concrete barriers and repairing and maintaining vehicles. The new troops will include military police, combat engineers and helicopter companies equipped with advanced technology to help detect people at night.

The extraordinary military operation comes a week before the Nov. 6 midterm elections as Trump has sought to transform fears about the caravan and immigration into electoral gains. On Tuesday, he stepped up his dire warnings, calling the band of migrants fleeing poverty and violence in Central America an “invasion.”

“Our Military is waiting for you!” he tweeted.

R. Gil Kerlikowske, Customs and Border Protection commissioner from 2014 to 2017, said the military cannot stop asylum seekers who show up at border crossings to seek protection, and that Border Patrol agents have had no trouble apprehending people who cross illegally.

“I see it as a political stunt and a waste of military resources and waste of tax dollars,” said Kerlikowske, who was at the helm during a major surge of Central Americans migrants in 2014. “To use active-duty military and put them in that role, I think is a huge mistake. I see it as nothing more than pandering to the midterm elections by the president.”

Traveling mostly on foot, the caravan of some 4,000 migrants and a much smaller group of hundreds more are still weeks, if not months, before reaching the U.S. border. Thousands have already dropped out, applying for refugee status in Mexico or taking the Mexican government up on free bus rides back home, and the group is likely to dwindle even more during the arduous journey ahead.

Another smaller caravan earlier this year numbered only a couple hundred by the time it arrived at the Tijuana-San Diego crossing.

And despite the heightened rhetoric, the number of immigrants apprehended at the border is dramatically lower than past years. Border Patrol agents this year made only a quarter of the arrests they made in 2000 at the height of illegal immigration, when the agency had half of the staffing it does today. The demographics have also drastically changed, from mostly Mexican men traveling alone, to Central American families with children.

Migrants arriving at the border will now see a sizable U.S. military presence — more than double the 2,000 who are in Syria fighting the Islamic State group — even though their mission will be largely a support role.

That’s because the military is bound by the Posse Comitatus Act, a 19th- century federal law that restricts participation in law enforcement activities. Unless Congress specifically authorizes it, military personnel can’t have direct contact with civilians, including immigrants, said Scott R. Anderson of The Brookings Institution.

Air Force Gen. Terrence O’Shaughnessy, head of U.S. Northern Command, said Tuesday that at least 5,239 troops were being sent to the Southwest border as the Pentagon works to meet requests from the Department of Homeland Security.

“The 5,239 are going forward and there will be additional forces over and above the 5,239,” he said, adding that number “is not the top line.”

Asked about the use of weapons, O’Shaughnessy said the active-duty troops have been given clear guidance on the use of force and there will be unit and individual training to make sure they know what they can and can’t do. Generally, U.S. troops are authorized to use force in self-defense.

Still, the large troop deployment will be limited to performing similar support functions as the National Guard troops Trump has already sent to the border.

These include 1,500 flight hours logged by about 600 National Guard troops in Arizona since they were deployed this spring. Members of the guard have also repaired more than 1,000 Border Patrol vehicles and completed 1,000 hours of supply and inventory, according to Customs and Border Protection.

In one case, a group of Border Patrol agents tracking drug smugglers in the remote Arizona desert in August called on a National Guard helicopter to keep an eye on the suspects and guide agents on the ground until they had them in custody. That operation resulted in several arrests and the seizure of 465 pounds of marijuana.

It remains unclear why the administration has chosen to send active-duty troops given that they will be limited to performing support functions.

O’Shaughnessy said there were about 1,000 troops already in Texas and that will grow to at least 1,800, likely by Wednesday. The deployments to Arizona and California will follow. All are going to staging bases in the states, and there are none at the border yet, he said.

It remains unclear why the administration was choosing to send active-duty troops given that they will be limited to performing the support functions the Guard already is doing.

The California National Guard has pledged up to 400 troops to the president’s border mission through March 31. Jerry Brown, the only Democratic governor in the four states bordering Mexico and a frequent Trump critic, conditioned his support on the troops having nothing to do with immigration enforcement or building border barriers.

Brown said the California troops would help fight transnational criminal gangs and drug and firearms smugglers.

In New Mexico, 118 Guard troops have been helping with vehicle maintenance and repair, cargo inspection operations, surveillance and communications.

Texas Gov. Greg Abbott pledged 400 troops to the border in April. Maj. Gen. John Nichols, the head of the Texas National Guard, told Congress in July that his troops served in a “variety of support roles,” including driving vehicles, security monitoring, and administration.

Associated Press writers Lolita Baldor, Robert Burns, Colleen Long and Jill Colvin in Washington; Susan Montoya Bryan in Albuquerque; Elliot Spagat in San Diego and Nomaan Merchant in Houston contributed to this report.