Preheat oven to 375°F (190°C) and grease a 9x13 inch baking dish.
In a medium saucepan, melt butter over medium heat. Whisk in flour and cook for 2 minutes to create a roux without browning.
Slowly whisk in the milk, salt, black pepper, onion powder, and garlic powder. Continue whisking until the sauce reaches a simmer and thickens.
Layer half of the sliced potatoes in the bottom of the prepared baking dish.
Top the potato layer with all of the minced onions and half of the diced ham.
Arrange the remaining potatoes over the ham layer and top with the remaining diced ham.
Pour the thickened white sauce evenly over the contents of the dish, ensuring the sauce penetrates between the layers.
Cover the dish tightly with aluminum foil and bake for 45 minutes.
Remove the foil and bake for an additional 30 minutes until the potatoes are tender when pierced with a fork and the top is golden brown.
Allow the dish to rest for 10 minutes at room temperature before serving to set the sauce.