I'm trying to hide a specific template associated with a site. So I have written some Powershell which gets the array of templates available to that web, copies the array to a new array while excluding the one I need to hide, and then sets the web to use the new array. Like this:
$web = "http://my.server/web"
$existing = $web.GetAvailableWebTemplates(1033)$new = @()
foreach($e in $existing | Where-Object { $_.name ne $template_2_hide})
{
$new += $e
}
$web.SetAvailableWebTemplates($new, 1033)
The final line is giving me an error which presumably means that the new array of objects is of the wrong type:
Cannot convert argument "0", with value: "System.Object[]", for "SetAvailableWebTemplates" to type "System.Collections.ObjectModel.Collection`1[Microsoft.SharePoint.SPWebTemplate]": "Cannot convert the "System.Object[]" value of type "System.Object[]" to type "System.Collections.ObjectModel.Collection`1[Microsoft.SharePoint.SPWebTemplate]".Can anyone help me please? Thanks!