Preheat your oven to 375°F (190°C).
Grease your baking dish with butter.
Melt butter in a saucepan over medium heat.
Whisk in flour until smooth and golden.
Slowly add milk while whisking constantly.
Stir in garlic powder, onion powder, salt, and pepper.
Let the sauce thicken for 3-4 minutes.
Remove from heat and mix in half the cheese.
Spread a layer of potatoes on the dish bottom.
Pour some cheese sauce over the potato layer.
Repeat layering until all potatoes are used.
Top with remaining shredded cheese.
Cover dish with foil and bake for 45 minutes.
Remove foil and bake uncovered for 20 minutes.
Garnish with parsley before serving warm.