Heat the oven to 350°F (175°C). Grease an 8x8-inch or 7x10-inch baking dish with butter.
Arrange half of the diced potatoes in a single layer in the bottom of the greased dish. Scatter 1 cup of the diced ham evenly over the potatoes.
In a small saucepan over medium heat, sauté the butter and onions for 4 minutes, until the onions become soft. Add the garlic and sauté for 1 minute. Incorporate the flour, salt, and pepper by whisking; continue cooking for 1 minute more. Turn the heat down to medium-low.
Gradually add the broth while whisking, then whisk in the milk until the mixture is smooth. Bring to a gentle simmer and stir in 1/2 cup of the cheese. Continue stirring until the sauce thickens. Adjust seasoning with salt and pepper to taste.
Pour half of the sauce over the potatoes in the baking dish. Add the remaining potatoes on top, distribute the remaining 1 cup ham over the potatoes, and finish with the remaining cheese sauce.
Tent with foil and bake for 45 minutes. Uncover, scatter the remaining 1/2 cup cheese on top, and continue baking for 15 minutes more, until the potatoes are tender when pierced with a fork and the cheese is bubbly.
Take out of the oven and allow to rest for 10 minutes before serving. Garnish with fresh parsley. Serve warm.