Preheat the oven to 375°F.
Heat a large pot of salted water to a boil over high heat. Prepare a large bowl of ice water.
Add the green beans to the boiling water and cook until nearly tender, about 5 minutes for fresh or 3 minutes for frozen. Drain green beans and transfer them to the ice bath for 2 minutes. Drain green beans again, pat them dry and add them to a 9x13 baking dish.
In a large saucepan over medium-high heat, melt the butter. Whisk in the flour, onion powder, garlic powder, salt, pepper, nutmeg and dijon, and cook, whisking occasionally, until fragrant, about 2 minutes.
Slowly whisk in the stock until smooth. Slowly whisk in the half and half until combined. Bring the mixture to a simmer over medium heat and cook until thickened, stirring occasionally, about 5 minutes.
Pour the sauce over the green beans and toss until fully coated.
Bake on center rack until sauce starts to bubble, about 20 minutes. Remove from the oven, toss the green beans and sprinkle with fried onions. Continue to bake on center rack until golden brown, about 10 more minutes.