kwizcom banner advertisement

Create Web Application in SharePoint 2013 using PowerShell

A web application in SharePoint acts as a container for one or more site collections. Web applications provide the link to the corresponding web site in IIS and to specific content databases in SQL Server for the storage of site collections and associated content.

How to Create a Web Application in SharePoint?
To Create new web application in SharePoint 2013, head on to SharePoint 2013 Central Administration site. Navigate to:
  • Application Management >> Manage web applications
  • Click on "New" button from the ribbon
  • Fill-out the details for your new web application. Such as: Web and click on "Create" to create a web application in SharePoint 2013.
    create sharepoint web application using powershell
Create Web Application in SharePoint 2013 using PowerShell:
Lets create a SharePoint web application using PowerShell. Here is my PowerShell script to create web application in SharePoint 2013:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Define Variables for Web Application Creation
$WebAppName = "Crescent Portal"
$HostHeader = "Portal.Crescent.com"
$WebAppURL = "http://"+$HostHeader
$WebAppPort = 80
$ContentDBName = "SP13_Content_Portal"
$AppPoolName = "Portal AppPool"
$AppPoolAccount = "Crescent\SP_Farm"
$AppPooPassword = "<<Password>>"

#Authentication Provider
$AuthProvider = New-SPAuthenticationProvider -UseWindowsIntegratedAuthentication -DisableKerberos

#Create new Managed Account
$SecurePassword = ConvertTo-SecureString -String $AppPooPassword -AsPlainText -Force
$cred = new-object -typeName System.Management.Automation.PsCredential -argumentlist $AppPoolAccount,$SecurePassword
New-SPManagedAccount -Credential $cred

#Create new Web Application
New-SPWebApplication -name $WebAppName -port $WebAppPort -hostheader $HostHeader -URL $WebAppURL -ApplicationPool $AppPoolName -ApplicationPoolAccount (Get-SPManagedAccount $AppPoolAccount) -AuthenticationMethod NTLM -AuthenticationProvider $AuthProvider -DatabaseName $ContentDBName

Lets make use of an existing managed account this time to create a sharepoint web application in powershell:
$AuthProvider = New-SPAuthenticationProvider -UseWindowsIntegratedAuthentication -DisableKerberos
New-SPWebApplication -Name "Crescent Portal" -Port 80 -HostHeader "portal.crescent.com" -DatabaseName "SP16_CrescentPortal_Content" -URL "http://portal.crescent.com" -ApplicationPool "Crescent Portal AppPool" -ApplicationPoolAccount (Get-SPManagedAccount "Crescent\Sp2016_Service") -AuthenticationProvider $AuthProvider

How about SSL Enabled Web Application?
$AuthProvider = New-SPAuthenticationProvider -UseWindowsIntegratedAuthentication -DisableKerberos
New-SPWebApplication -Name "Crescent Internet" -ApplicationPool "Crescent Internet AppPool" -ApplicationPoolAccount (Get-SPManagedAccount "Crescent\SPS2016_AppPool") -URL "https://crescent.com" -Port 443 -HostHeader "crescent.com" -DatabaseName "SP16_CrescentInternet_Content01" -Path "C:\Crescent_Internet" -SecureSocketsLayer -AuthenticationProvider $AuthProvider

This creates a new web application using PowerShell for SharePoint 2010, SharePoint 2013 or SharePoint 2016. But wait! You are not yet done. You got to create the root site collection for the web application. If you try to browse to the web application without creating top-level site collection, you'll get "HTTP 404" error!

Create Top-Level Site Collection with PowerShell:
#Create Top-Level Site collection in SharePoint 2013
$SiteURL="http://portal.crescent.com"
$SiteName="Crescent Portal"
$SiteOwner="Crescent\SP_Farm"
$SiteTemplate="STS#0"

#Create new Site collection
New-SPSite –url $SiteURL -Name $SiteName -OwnerAlias $SiteOwner -Template $SiteTemplate

Although this script is written to create web application with PowerShell for SharePoint 2013, It can be also used in creating a web application for SharePoint 2010 & SharePoint 2016 too.

SharePoint 2013 PowerShell to create web application in classic mode:
Just leave the AuthenticationProvider parameter in the above script to create new web application in classic mode.

You must keep number web applications and IIS websites as low as possible for better performance! Do not create more than 20 web applications per SharePoint server farm. If you need to provide multiple paths to your sites, use host-named site collections instead of creating additional web application.
Create Web Application in SharePoint 2013 using PowerShell Create Web Application in SharePoint 2013 using PowerShell Reviewed by Salaudeen Rajack on 1:29 PM Rating: 5

2 comments:

  1. what is the command for formsbased authentication ?

    ReplyDelete
    Replies
    1. Use: $ap = New-SPAuthenticationProvider -Name "ClaimsForms" -ASPNETMembershipProvider -ASPNETRoleProviderName

      Delete

Please Login and comment to get your questions answered!

Powered by Blogger.