Restrict the New Site Available Templates with Powershell

I recently had to work on a project where I had to only let users create “New Site” with only a few numbers of Templates.  You can easily do it by the GUI, but how do we do it in PowerShell?

Here is a picture of the “New Site” GUI before running the Powershell Script.

New Site Available Templates (opens in a new tab)

Now here is the script.

$mainurl = “http://vlad.test.loc” (opens in a new tab)
$Web = Get-SPWeb $mainurl

$Web.AllProperties[“__WebTemplates”] = “”
$Web.Update()

Also if you want to use a Custom Template you can use this syntax.

#$Web.AllProperties[“__WebTemplates”] = “”

This is how the “New Site” GUI looks after the script.

New Site Available Templates (opens in a new tab)

We just set the Available Templates to “Team Site”, “Blank Site” and “Document Workspace”.

If you have any questions, you can ask in the comments I will answer as fast as possible 🙂