Preheat the oven to 375°F and lightly grease a 9x13-inch baking dish.
Layer the diced potatoes, diced ham, and chopped onions in the prepared baking dish.
In a mixing bowl, whisk together the soup, milk, sour cream, flour, melted butter, garlic powder, onion powder, salt, and black pepper until smooth.
Pour the soup mixture over the potatoes, ham, and onions, making sure to cover everything.
Sprinkle 1 cup of the shredded cheddar cheese on top of the casserole.
Cover the dish with foil and bake for 35-40 minutes.
Remove the foil and give it a mix. Add the remaining 2 cups of cheese. While uncovered, bake for an additional 5 minutes, or until the cheese is melted and bubbly and the potatoes are tender.
Allow the casserole to cool for a few minutes before serving. The sauce will continue to thicken up during this time.