Preheat the oven to 375°F with a rack in the center position.
Bring a large pot of salted water to a boil over high heat and prepare a large bowl of ice water. Once the water is boiling, add the green beans and cook until almost tender, about 3 minutes for fresh or 2 minutes for frozen. Drain green beans and transfer them to the ice bath for 2 minutes. Drain green beans, pat them dry, and add them to a 9x13-inch baking dish.
Add the butter to a large saucepan set over medium-high heat. Once the butter is melted, whisk in the flour, onion powder, garlic powder, salt, pepper, nutmeg, and mustard. Cook, whisking occasionally, until fragrant, about 2 minutes.
Slowly whisk in the stock until smooth. Slowly whisk in the half and half, then bring to a simmer over medium heat. Cook until thickened, stirring occasionally, about 5 minutes. Pour over the green beans and toss to coat.
Bake until sauce starts to bubble, about 20 minutes. Remove from the oven, toss the green beans, and sprinkle with fried onions. Return to the oven until golden brown, about 10 more minutes.