PowerShell to Delete a site collection in SharePoint 2013

Delete a site collection in SharePoint 2013 using PowerShell

If you are deleting a SharePoint site collection, you may lose your all subsites under the site collection . When you delete a site collection, you permanently destroy all the content and the user information, as shown below.

  • Documents and document libraries.
  • Site configuration settings and user profile Service configurations.
  • Groups, Role and security information, which is related to the website.
  • Sub sites of the top-level website, their contents and user information.

To avoid any data loss, first try to take backup your site collection, then try these powerful commands.

Remove-SPSite -Identity <“Site URL”> GradualDelete

Create a site collection in SharePoint 2013 Usin PowerShell

A site collection is a grouping/collection of the Websites under a common top-level

After you create a site collection, a top-level site is automatically created in the site collection. You can then create one or more sub sites under the top-level site in SharePoint2013.

Before we use this SharePoint Management Shell, the admin should be a user of Shell access db_owner.

For this, we have to use this command to add the user to the admin role.

Syntax

Add-SPShellAdmin [-UserName] <String> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-database <SPDatabasePipeBind>] [-WhatIf [<SwitchParameter>]]

When you run this cmdlet to add a user to the SharePoint_Shell_Access role,

  • User must have membership in the securityadmin fixed Server role on the SQL Server instance.
  • User must have membership in the db_owner fixed database role on all affected databases.
  • User must have local administrative permission on the local computer.

Example

Add-SPShellAdmin -UserName OGInfo\spfmadm

Create a site collection in SharePoint 2013

  • Open your SharePoint Management Sh
  • ell in your system.
  • Copy the code given below.
  • Run it.

Get-SPWebTemplate$template = Get-SPWebTemplate “STS#0”

New-SPSite -Url <SiteURL> -OwnerAlias <domain\username> -Template $template.

This will create a new site collection. Here, we used Team site Template “STS#0”

List of SharePoint 2013 Template sites

Here, the codes are given below, which are to be used in SharePoint site creation and use this template ID, which is based on your requirement.

Template ID Title
GLOBAL#0 Global template
STS#0 Team Site
STS#1 Blank Site
STS#2 Document Workspace
MPS#0 Basic Meeting Workspace
MPS#1 Blank Meeting Workspace
MPS#2 Decision Meeting Workspace
MPS#3 Social Meeting Workspace
MPS#4 Multipage Meeting Workspace
CENTRALADMIN#0 Central Admin Site
WIKI#0 Wiki Site
BLOG#0 Blog
SGS#0 Group Work Site
TENANTADMIN#0 Tenant Admin Site
APP#0 App Template
APPCATALOG#0 App Catalog Site
ACCSRV#0 Access Services Site
ACCSRV#1 Assets Web Database
ACCSRV#3 Charitable Contributions Web Database
ACCSRV#4 Contacts Web Database
ACCSRV#5 Projects Web Database
ACCSRV#6 Issues Web Database
ACCSVC#0 Access Services Site Internal
ACCSVC#1 Access Services Site
BDR#0 Document Center
DEV#0 Developer Site
DOCMARKETPLACESITE#0 Academic Library
EDISC#0 eDiscovery Center
EDISC#1 eDiscovery Case
OFFILE#0 (obsolete) Records Center
OFFILE#1 Records Center
OSRV#0 Shared Services Administration Site
PPSMASite#0 PerformancePoint
BICenterSite#0 Business Intelligence Center
SPS#0 SharePoint Portal Server Site
SPSPERS#0 SharePoint Portal Server Personal Space
SPSPERS#2 Storage And Social SharePoint Portal Server Personal Space
SPSPERS#3 Storage Only SharePoint Portal Server Personal Space
SPSPERS#4 Social Only SharePoint Portal Server Personal Space
SPSPERS#5 Empty SharePoint Portal Server Personal Space
SPSMSITE#0 Personalization Site
SPSTOC#0 Contents area Template
SPSTOPIC#0 Topic area template
SPSNEWS#0 News Site
CMSPUBLISHING#0 Publishing Site
BLANKINTERNET#0 Publishing Site
BLANKINTERNET#1 Press Releases Site
BLANKINTERNET#2 Publishing Site with Workflow
SPSNHOME#0 News Site
SPSSITES#0 Site Directory
SPSCOMMU#0 Community area template
SPSREPORTCENTER#0 Report Center
SPSPORTAL#0 Collaboration Portal
SRCHCEN#0 Enterprise Search Center
PROFILES#0 Profiles
BLANKINTERNETCONTAINER#0 Publishing Portal
SPSMSITEHOST#0 My Site Host
ENTERWIKI#0 Enterprise Wiki
PROJECTSITE#0 Project Site
PRODUCTCATALOG#0 Product Catalog
COMMUNITY#0 Community Site
COMMUNITYPORTAL#0 Community Portal
SRCHCENTERLITE#0 Basic Search Center
SRCHCENTERLITE#1  Basic Search Center
SRCHCENTERFAST#0 FAST Search Center
visprus#0 Visio Process Repository