Update: thisThis is the current script, based on the feedback in the comments:
I checked, and the templates are the same in both places. I don't have powershell access on the PRD machine, so I cannot do any debugging, but the only thing that I can think of is that there are multiple templates with the same title, that are not visible neither in the GUI nor in Designer. I am not sure if this is even possible, but can someone help me how to return the last, active template with this line:
$wtemplate = $web.GetAvailableWebTemplates(1033) | Where-Object {$_.Title -eq $Template}
Ideas for other root cause are also very welcome.
Update 2:Update: Looks like we indeed have double templates with the same title, but different names. However, these extra templates are not visible under "solutions" or in Designer, onder site templates like:
Name Title
{A248FF57-5248-4C8B-9459-1B62703DACCD}#Customers Customers
{CC69A307-7F92-47A7-8B6F-3981B480F9EA}#Customers Customers
So, the task is to remove one of these templates, but I did not find any code that removes a web template by name. The Uninstall-SPSolution accepts the wsp file name as parameter, but there is only one customer.wsp in the solutions library, so this will probably remove both.