Preheat oven to 350 degrees F. Coat a 9x13 oven safe baking dish with nonstick spray.
Melt butter in a large skillet over medium heat. Then add onions and cook approximately 5 minutes, until softened. Add garlic and cook an additional minute, stirring frequently.
Whisk in milk and cook an additional 5 minutes, continuously stirring, until bubbly and thickened.
Whisk in salt, pepper and cheese and continue stirring until cheese is melted then remove pan from heat.
Place half the sliced potatoes evenly in the bottom of your baking dish.
Place half the diced ham over the top of the potatoes, evenly distributed.
Pour half the sauce over the ham evenly.
Repeat these layers, adding the remaining potatoes, then ham, then cheese sauce over the top.
Cover baking dish with foil and cook for 45 minutes. Uncover and bake an additional 20-30 minutes until bubbly and potatoes are soft and tender.