Add Alternate Access Mapping URL to Host Named Site Collection Zone

Requirement: Add new URL to Host named site collections alternate access mappings.
In a  SharePoint hosting Web application, once sites are provisioned from the hosting control panel, We got to manually add an internet zone URL with “HTTPS” to make it available over the Internet.

Host named site collection alternate access mapping
Host-named site collections are enhanced in SharePoint 2016 to allow you to add multiple URLs by using the Set-SPSite cmdlet.

  • Set-SPSiteUrl – Adds new top-level URLs to a host named site collection
  • Get-SPSiteUrl – Gets the list of all the top-level URLs assigned to a host named site collection.
  • Remove-SPSiteUrl – This enables you to remove a top-level URL assigned to a host named site collection.

How to Add AAM URL to Host Named Site Collection’s Zone?

Here is an example of adding alternate access mapping to a host-named site collection.

$Site = Get-SPSite ""
Set-SPSiteURL -Identity $Site -URL "" -Zone Internet

PowerShell script to Add new URL to internet zone for a host-named site collection:
For my requirement, I had to scan for all host-named site collections to check if the site has a URL mapping for the Internet zone. If not, add a URL to the Internet zone of the Host named site collection.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$OutPutFile = "D:\Scripts\Log.txt"
#Get All Host Named Sites of the Hosting Web Application
$SitesColl = Get-SPSite -Limit $All | Where-Object {$_.HostHeaderIsSiteName -eq $true} 

#Loop through each site
ForEach($site in $SitesColl)
    #Check if site created in Internet Zone
    if( (Get-SPSiteURL -Identity $site.Url | Where Zone -eq "Internet").count -eq 0)
        Set-SPSiteURL -Identity $site.URL -Zone Internet -Url ($site.Url -replace "http", "https")
        Write-host "Created Internet Zone for site:"$site.Url 

        #Append to a Log
        "Created Internet Zone for site: $($site.Url) on $(get-date)" >> $OutPutFile

We scheduled the script to run every 5 minutes using the Windows Task scheduler.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

Leave a Reply

Your email address will not be published. Required fields are marked *