Preheat oven to 400 F.
Prepare a 9 X 13 baking pan with spray oil, such as Pam.
Scrub and slice the potatoes. I like to peel mine, but peeling is optional. Slice thin and make the potato sizes close to the same size for even cooking.
Chop the onions.
In a saucepan over medium-high heat, melt the butter. Add the flour and whisk until incorporated.
Add the milk and cook 3-4 minutes continuing to whisk. Add the pepper and if you wish (salt) at this point. Turn off the heat.
Begin layering the ingredients. Add about 1/3 of the potatoes, top with the part of the onions , ham and cheese. Repeat the layering once more.
Add the sauce and finish adding the cheese to the top.
Cover with aluminum foil (spray with oil such as Pam to prevent the cheese from sticking).
Bake at 400F for 30 minutes. Reduce heat to 350F and bake until the potatoes are fork tender. Approximately 90 minutes. The casserole should be nice and bubbly. Allow to set for about 10 minutes before serving.