In 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.
SharePoint Tutorial Contents
- What is a web application in SharePoint?
- new-spwebapplication
- Create web application SharePoint 2016/2019 PowerShell
- Create web application using PowerShell in SharePoint 2013
- Create site collection SharePoint 2016 PowerShell
- Get all Sites and subsites under web application using PowerShell in SharePoint
- Get SharePoint Site Collection or Site Created Date using PowerShell
- Create a Web Application in SharePoint 2016 from Central Administration
A SharePoint web application is a collection of one or more IIS websites configured to map incoming HTTP requests to a set of SharePoint sites. A SharePoint 2016/2013 web application is composed of an Internet Information Services (IIS) web site that acts as a logical unit for the site collections that you create.
The web application also maps each SharePoint site to one or more specific content databases. SharePoint Foundation uses content databases to store site content such as list items, documents, and customization information.
When you create a web application in SharePoint Foundation, it creates an IIS website with a root folder containing a web.config file at the following location:
C:\inetpub\wwwroot\wss\VirtualDirectories
Let us see, how to create a web application and site collection in SharePoint 2016/2013.
new-spwebapplication
In PowerShell, we can use the new-spwebapplication cmdlets to create a web application in SharePoint server like SharePoint 2010, SharePoint 2013, SharePoint 2016, and SharePoint 2019.
Syntax:
Below is the minimum syntax to create a web application in SharePoint. These are the minimum parameters:
New-SPWebApplication -ApplicationPool <String> -Name <String>
There are also other parameters are available, you can check in this msdn url.
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
This is how we can create a web application using PowerShell in SharePoint 2013/2016/2019.
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.
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"
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:
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
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.
This way we can get SharePoint site collection created date using PowerShell.
We can create a web application by using the SharePoint central administration website or we can also create a web application using PowerShell. In large enterprises, usually use PowerShell to create a web application.
The user must be a member of the Farm Administrators SharePoint group to create a web application. To verify open SharePoint 2016 central administration web site. Then click on “Manage the farm administrators group” which is under the Security section.
Now to create a web application, from the SharePoint 2016 Central Administration home page click on the “Manage web applications” link which is under “Application Management”.
Then from the Ribbon click on New Web Application to create a new web application. In the create new web application dialog box, fill the below things to create a new SharePoint web application.
Claims Authentication Types
Choose Enable Windows Authentication and Integrated Windows authentication [NTML]
Sign In Page URL
In the Sign in Page URL, choose Default Sign In Page.
Public URL:
Give a public URL for the web application, by default it will come as http://ServerName:Port
Ex: http://MYPC:27214/
Application Pool:
Choose, Create new application pool.
By default, it will create an application pool the same name as your web application.
Provide Security Account for an application pool.
Database Name and Authentication:
Give the Database Server name
And Database Name
Choose Windows Authentication
Failover Server:
Leave Blank
Service Application Connections
Select the service applications you want to activate the Customer Experience Improvement Program:
Choose No.
Then click on OK to create the web application. It will take some time to create a web application. Once created successfully, it will display a message. Once the web application is ready we can create our site collection.
You may like following SharePoint PowerShell tutorials:
- Bulk SharePoint Online Site Collection Creation using PowerShell
- 3 Different ways to Change Site Collection URL in SharePoint using PowerShell
- SharePoint 2016 Fast Site Collection Creation using PowerShell
- Delete corrupted SharePoint site collection using PowerShell
- SharePoint 2013/2016: Get all ListTemplates from Site collection using PowerShell
- Backup and Restore Site collection in SharePoint 2016/2013/2010/2007
- Extend web application in SharePoint 2013
- Delete Hidden Web Application in SharePoint 2013 using PowerShell
- SharePoint BCS step by step
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.
Bhawana Rathore is a Microsoft MVP (3 times in Office Apps & Services) and a passionate SharePoint Consultant, having around 10 years of IT experience in the industry, as well as in .Net technologies. She likes to share her technical expertise in EnjoySharePoint.com and SPGuides.com
[…] SharePoint 2016 Create a web application and a Site Collection using PowerShell […]