Last week I wrote about how to create a new SharePoint Web Application using PowerShell. That was quite straight forward and there are a couple of post about it. But when I did a quick search for how you extend a Web Application I did not find anything at all.
It’s a bit more tricky but when you find out how to do it, it is actually not that difficult.
When we created a brand new Web App we used the SPWebApplicationBuilder class. When we want to extend we use the SPWebApplication and make a Lookup towards the site to extend this looks like below:
We then need to prepare for the creation by setting a couple of objects and variables to use later. The $SecureBinding is for SSL and the $ServerBinding is for the general IIS bindings like Port and host header. In this case we will extend the Web Application and use port 8080 and not use SSL or Anonymous access.
The last thing we need to do is to decide what Zone to use. The Zones in SharePoint is a way to segment and the web applications and for instance put different access rights to them. The options you have is Default, Internet, Intranet, Extranet and Custom so that is the values you can use.
$ServerBinding = new-object microsoft.sharepoint.administration.SPServerBinding
$ServerBinding.Port = 8080
$SecureBinding = $null
$ExtendWebAppAllowAnonymous = $false
$ExtendWebAppPath = “C:\Inetpub\wwwroot\wss\VirtualDirectories\ExtendedSite”
$ZoneType = “Extranet”
$Zone = [microsoft.sharepoint.administration.SPURLZone]::$ZoneType
Next thing to do is to create a new SPIisSettings object and insert our settings.
$ExtendWebApplication.IisSettings.Add($Zone, $SPSettings)
Afther we have added the new IIS site we need to add the Alternate Access Mappings and provision it. We use the SPAlternateURL and send the loadbalancer and Zone info to it.
$AltUrl = new-object microsoft.sharepoint.administration.SPAlternateUrl($LoadBalancerURL, $Zone)
$ExtendWebApplication.AlternateUrls.SetResponseUrl($AltUrl)
$ExtendWebApplication.AlternateUrls.Update()
$ExtendWebApplication.Update()
$ExtendWebApplication.ProvisionGlobally()
If you have more then one servers use the ProvisionGlobally() otherwise you can use the Provision()
Steal with pride!









Great post… good suggestions…thanks!
[...] two earlier posts I have written about how to create and extend a web application using PowerShell. Today I ran in to a problem when I extended a Web Application [...]