Set the oven's temperature to 375. Apply cooking spray to a 13 x 9-inch baking dish to grease it.
Arrange a layer of potatoes in the baking dish and sprinkle with half of the chopped onions and roughly ¼ teaspoon of salt.
Arrange half of the ham in a layer in the baking dish, and then add another layer of potatoes, onions, and ¼ teaspoon of salt on top.
After adding a second layer of ham, spoon the leftover potatoes on top.
Melt the butter in a saucepan over medium heat, then whisk in the flour, pepper, and the remaining salt. Continue whisking for 30 to 45 seconds.
Slowly whisk in the heavy cream and milk until it thickens, which should take two to three minutes.
Cover the potatoes with aluminum foil and bake for 45 minutes, adding the cream sauce on top.
After covering the potatoes with grated cheddar, bake them uncovered for a further twenty-five minutes.