SharePoint 2019/2016/2013: Create a web application and a Site Collection using PowerShell

This PowerShell SharePoint tutorial, we will discuss how to create a web application in SharePoint 2019/2016/2013 using PowerShell, also we will see how to create a site collection using PowerShell in SharePoint 2016/2013.

If you want to try out SharePoint 2016/2019, then you can see the SharePoint 2016 installation steps, new features of SharePoint 2016 and you can download a free PDF on SharePoint 2019 installation and new features.

Recently after installing SharePoint 2016 on my personal laptop, when I was trying to create a web application using the browser I was getting a continuous timeout exception, So before installing SharePoint 2016 make sure to check SharePoint 2016 hardware and software requirements.

So I tried PowerShell to create a web application and site collection in SharePoint.

Create web application SharePoint 2016/2019 PowerShell

Below PowerShell command to create a web application using PowerShell in SharePoint 2016/2019:

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
$authentication = New-SPAuthenticationProvider -UseWindowsIntegratedAuthentication -DisableKerberos
New-SPWebApplication -Name "My SP2016 Web App" -Port 33779 -ApplicationPool "MySP2016AppPool" -ApplicationPoolAccount (Get-SPManagedAccount "MYSP\Administrator") -AuthenticationMethod NTLM -AuthenticationProvider $authentication
create web application sharepoint 2019 powershell

This is how we can create a web application using PowerShell in SharePoint 2013/2016/2019.

Create web application using PowerShell in SharePoint 2013

We can create a web application by using a browser from SharePoint 2013 central admin as well as we can create a web application through PowerShell.

Below is the PowerShell command to create a web application in SharePoint 2013. You can write, run and debug the PowerShell script using PowerShell ISE.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction "SilentlyContinue"

$name = "My Test Web Application"
$port = 80
$hostHeader = "intranet.enjoysharepoint.com"
$url = "http://intranet.enjoysharepoint.com"
$appPoolName = "SharePoint Default Appl Pool"
$appPoolAccount = Get-SPManagedAccount "EnjoySharePoint\SP_Admin"
New-SPWebApplication -Name $name -Port $port -HostHeader $hostHeader -URL $url ' -ApplicationPool $appPoolName ' -ApplicationPoolAccount $appPoolAccount

Once you will execute the command, it will create a web application in SharePoint 2013.

Create site collection SharePoint 2016 PowerShell

Below PowerShell command to create a site collection using PowerShell in SharePoint 2013/2016/2019.

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
New-SPSite http://sp2016:33779/ -OwnerAlias "MYSP\Administrator" -Name "My SP2016 Site Collection" -Template "BLANKINTERNET#0"
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
New-SPSite http://sp2016:33779/sites/MySP2016SiteCollection -OwnerAlias "MYSP\Administrator" -Name "My SP2016 Site Collection" -Template "STS#0"
create site collection sharepoint powershell

Get all Sites and subsites under web application using PowerShell in SharePoint

Now, we will see how to get all the sites and subsites under a web application using PowerShell in SharePoint 2013/2016. Here we will pass the SharePoint web application URL and it will give all the sites and subsites under it as well as the site URL, Title, and Created date.

Below is the PowerShell command to get all sites and subsites under the web application in SharePoint 2013/2016.

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
Get-SPSite -WebApplication http://win-pfcp2dgt8di/ -Limit All |
Select -ExpandProperty AllWebs | ft url, Title, Created -auto

The results will appear like below:

Get all Sites and subsites under web application using PowerShell in SharePoint

If you want to export the results into CSV then you can write like below:

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
Get-SPSite -WebApplication http://win-pfcp2dgt8di/ -Limit All |
Select -ExpandProperty AllWebs | ft url, Title, Created -auto > E:\AllSites.csv

Get SharePoint Site Collection or Site Created Date using PowerShell

Here, we will see how to get the SharePoint site collection or site created date using PowerShell in SharePoint 2013/2016. It is not possible to get the SharePoint site created date by using the browser. So it will be helpful to get SharePoint site creation information using PowerShell.

Also, we will see how to get all sites and subsites under a web application using PowerShell in SharePoint. And we will see, how to get SharePoint site collection or site created date using PowerShell.

Below is the PowerShell command to get the SharePoint site created date. It will display all the SharePoint site collection and site created date using PowerShell in SharePoint 2013/2016.

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
Get-SPSite -Limit All | %{$root = $_.rootweb; $date = $root.created.toShortDateString(); Write-Host "Site URL: $($root.url) Created Date: $($date)"}

It will display the results like below, it shows Site collection and all subsite created date using PowerShell in SharePoint 2013/2016.

Get SharePoint site collection created date PowerShell

This way we can get SharePoint site collection created date using PowerShell.

You may like following SharePoint PowerShell tutorials:

This SharePoint tutorial we learned, how to create a web application in SharePoint using PowerShell, also we saw how to create a site collection using PowerShell in SharePoint 2013/2016/2019.

Also, we learned how to get all Sites and subsites under web application using PowerShell in SharePoint 2013/2016/2019.

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

  • […] SharePoint 2016 Create a web application and a Site Collection using PowerShell […]

  • >