Preheat the oven to 375°F and grease your baking dish.
Peel the potatoes and slice them thinly.
Melt butter in a saucepan over medium heat.
Stir in flour and whisk until smooth and bubbly.
Slowly add milk, whisking to prevent lumps.
Add garlic powder, onion powder, salt, and pepper.
Stir until the sauce thickens, then remove from heat.
Layer half the potatoes in the prepared baking dish.
Top with half of the ham and half of the cheese.
Repeat the layers with remaining potatoes, ham, and cheese.
Pour the thickened sauce evenly over the whole dish.
Cover the dish with foil and bake for 45 minutes.
Remove the foil and bake another 20–25 minutes.
Let the dish rest for 10 minutes before serving.