Preheat the oven to 400 degrees Fahrenheit. Prepare a 9X13 baking dish by spraying it with cooking spray.
Place one layer of sliced potatoes on the bottom of the baking dish. Sprinkle on ¼ of the sliced onions on top of the potato layer. Repeat with the potatoes and onions until you have used all of the potatoes and onions. Set aside.
In a medium saucepan over medium high heat, melt the unsalted butter and whisk in the flour. Continue to whisk for one to two minutes.
Add in the garlic powder, onion powder, dried basil, dried rosemary, and pepper. Whisk together.
Slowly whisk in the heavy cream and cook until thickened, stirring frequently.
Dump all the cheese into the saucepan and mix until the cheese is completely combined.
Pour the cheese sauce over the potatoes and onions in the baking dish.
Cover the pan with aluminum foil and bake in the oven for 50 minutes.
Take off foil and return pan to oven for an additional 10 minutes or until the top is set and the sides are bubbly.
Garnish with chopped parsley (optional) and then plate and serve. Best when served warm.