Skip Ribbon Commands
Skip to main content

SharePoint Lover


SharePoint Lover > Posts > SharePoint 2010 PowerShell Commands for Removing SharePoint Sites
September 27
SharePoint 2010 PowerShell Commands for Removing SharePoint Sites

Here are a few of my post popular commands for performing actions on a SharePoint 2010 site using SharePoint PowerShell


Creating a site template from an existing site template using Windows PowerShell.


Although the front end gives you a very good way of achieving this, there are times when you would like to achieve this using PowerShell instead of clicking the numerous buttons and screens. This applies if you already have created a SharePoint site template and you want to create several (Believe me, I've had to create 50 sites from a Template, and doing it from the front end was rather painful and time consuming).

This will show you a list of all the site GUID's of that site collection as well as the GUID of the template that you want to use to create extra sites.

  1. Get the reference of the SharePoint Template using the following Windows PowerShell commands

    $url = https://sharepointlover/SharePointLoverSiteCollection/SharePointLoverTeamSiteTemplate (Customise this to your own site URL)

    $site= new-Object Microsoft.SharePoint.SPSite($url )

    $loc= [System.Int32]::Parse(1033)

    $templates= $site.GetWebTemplates($loc)

    foreach ($child in $templates){ write-host $child.Name " " $child.Title}


  2. From the list displayed, check for the GUID of the site template that you want to create a template for e.g. SharePointLoverTeamSiteTemplate.

    They should normally be located at the bottom of the screen

    {73B9C675-F3DA-4509-90E8-0D6EEA6A8D2C}#SharePointLoverTeamSiteTemplate SharePointLoverTeamSiteTemplate

    {1B765F83-3380-4CF5-9CE9-5180D3351B30}#SharePointLoverTeamSiteTemplatev1 SharePointLoverTeamSiteTemplatev1

  3. Next, launch Windows PowerShell and enter the script to create a new Team Site


    $web = New-SPWeb https://sharepointlover/SharePointLoverSiteCollection/SharePointLoverNewSite


  4. Next enter the following Windows PowerShell Script to apply the Team site template that you had referred to earlier on in step 1




    Please note – you don't need to enter the Team Site that you want to create in again as this is now stored as a variable in $web.


    If you navigate to your site now, the site would now have been created with the template that you selected.



Removing the site that you have just created using Windows PowerShell.


I also ran into a situation whereby I needed to delete the SharePoint Site I had just created. Again rather than doing this from the front end, use the PowerShell command Remove-SPWeb (although be careful to realise that you are deleting the web site


Remove-SPWeb -Identity https://sharepointlover/SharePointLoverSiteCollection/SharePointLoverNewSite


This will permanently delete the site "SharePointLoverNewSite"



Creating a new site from an existing Site.


Sometimes, you may want to duplicate an existing site (i.e. not a site template) and duplicate all of the content of this site into another site (i.e. create a new site with the site contents of the source site. You might have thought that you could achieve this with SharePoint Designer 2010 or even with the front end, but unfortunately this can only be done by SharePoint Management Shell.


  1. Launch SharePoint Management Shell as an Administrator
  2. Enter the PowerShell Command below to get and reference the source site


    $Web=Get-SPWeb https://sharepointlover/SharePointLoverSiteCollection/SharePointLoverTeamSite


  3. Enter this PowerShell Script into SharePoint Management Shell to create the new Team Site

$Web.SaveAsTemplate("SharePointLoverTeamSite"," SharePointLover TeamSite ","Template for creating SharePoint Lover Sites",1)

Which equates to the site folder name to be created | The Website name | A description of the new site created | 1 –if you want content and 0 for no content


There are no comments for this post.