Hello everyone,
If you want to create a new site collection in SharePoint 2013 through code or PowerShell. Then use below code or PowerShell script. This will help you to create brand new site collection under your web application.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
// 1. Create site collection using server object model
namespace CreateSiteCollection
{
class Program
{
public const string siteUrl = "http://myserver:5263"; //url_Of_your_Web_application
static void Main(string[] args)
{
SPSite site=new SPSite(siteUrl);
// for create your site collection get object of web application class
SPWebApplication webapp = site.WebApplication;
// for create a brand new site collection use Add() method to add new site collection
webapp.Sites.Add
(
"/sites/Training", // site_url ,
"Training Site", // Title,
"SPS 2013 Training", // Description ,
1033, // us-eng_code,
"STS#0", // type_of_site_template,
@"Tabrez Ajaz", // owner_of_site_collection,
"Administrator", // type
"tabrez@xyz.com" //owner email
);
Console.WriteLine("New Site Collection Created Name : Tabrez Site");
Console.ReadKey();
}
}
}

Creating a Site Collection through PowerShell script:
- Get-SPWebTemplate – Get all template name
- $template = Get-SPWebTemplate "STS#0" --> where: "STS#0" means Team Site
- New-SPSite -Url "http://dsknomoe12:5566/" -OwnerAlias "myPC\Username" -Template $template
where:
$template contains type of template for create your site collection
"STS#0" means Team Site
"http://dsknomoe12:5566/" -> url of you site
That's it all done.