Melt the butter in a 12-inch skillet over medium heat. Add the onion and cook for 1 minute. Add the mushrooms, raise the heat to high, and continue cooking, stirring as needed, for 5 minutes. Add the garlic, ½ teaspoon of the salt and ½ teaspoon of the pepper. Remove from the heat and set aside.
Generously coat a 6-quart slow cooker with cooking spray. Shingle the potatoes in two with ½ teaspoon of the salt and ½ teaspoon of the pepper. Top the potatoes with half of the mushrooms-onion mixture and gently spread it out in an even layer. Arrange half of the ham slices over the potatoes, top with half of the Gruyere, and pour in half of the chicken stock. Repeat with the remaining potatoes, salt, pepper, mushrooms mixture, and ham. Add the remaining ½ cup chicken stock. Using a metal spatula, gently press the ingredients so the layers are even. Tuck the thyme sprigs around the edges.
Cook on high for 4 hours, or until the potatoes are tender. You can test for doneness by inserting the blade of a thin knife into the center. There should be little resistance.
Drizzle in the heavy cream and cook for another 30 minutes.
When the casserole is done, top it with the remaining Gruyere and the fresh thyme leaves. Turn off the cooker. Allow the potatoes to cool enough to set before serving, about 1 hour, covered.