In preparing to shoot Brad Pitt starrer “War Machine,” which Netflix releases May 26, edgy Australian auteur David Michod made it a top priority that his account of the U.S. offensive in Afghanistan during the lead-up to the 2010 firing of U.S. Army Gen. Stanley McChrystal, though satirical, be immersed in a naturalistic backdrop.

“Producer Ian Bryce contacted us and said, ‘Can you get your hands on U.S. military equipment?’” recalls “War Machine” line producer Michael Flannigan. “A couple of phone calls later the answer was yes, thanks to the Abu Dhabi Film Commission and the United Arab Emirates government.”

For the commission, which has attracted several big Hollywood pics, including “Star Wars: The Force Awakens” and “Furious 7,” “War Machine” posed a particular challenge. “It’s the first time we’ve experienced a war movie with the military,” says commission chief Jassim Al Nowais.

Adds Flannigan, “The UAE military was tremendously helpful not just in providing the equipment we used — the aircraft and vehicles — but also in getting explosives in and out of the country.”

Based on the best-selling book “The Operators: The Wild and Terrifying Inside Story of America’s War in Afghanistan,” by late American journalist Michael Hastings, “War Machine” was produced by Netflix and Pitt’s production company, Plan B Entertainment, on a reported $60 million budget. It filmed for 22 days in Abu Dhabi at the end of 2015, tapping into the commission’s 30% rebate and marking the longest Hollywood shoot in the UAE to date. In the film, Pitt plays U.S. Gen. Glen McMahon, a character based on McChrystal.

The production used 2,300 extras of more than 20 nationalities, coordinated by casting agency Miranda Davidson Studios, based in twofour54, Abu Dhabi’s tax-free media and entertainment zone, which promotes the film industry in the region. Roughly 1,000 of those extras were UAE military, who attended a special boot camp. Hundreds of others were Afghans who had fled their country and found refuge in the Emirates.

Scouting for the UAE-based Afghans who met Michod’s meticulous specifications was time-consuming but emotionally rewarding, says casting agent Miranda Davidson. “My guys went into their village, and we were going to bus a bunch of them back to the twofour54 offices to interview them, but they were terrified that we were recruiting them for ISIS,” Davidson says. During auditions, when the extras were asked to “bash America” they kept saying, “No, no, no!” she says. It took her team several months to establish a rapport and gain their trust.