Introduction

In this article, we will discuss how to use PowerShell cmdlets for managing Alternate Access Mapping in SharePoint Farm. Another article from the real world examples series in which we will explain how to use SharePoint 2016 PowerShell commands. We will try to cover all the available cmdlets i.e Get, New, Set, and Remove.

Scenario

KrossFarm wants to update the Url of their web application, due to a change of their DNS conflict issue along with Authentications for different zones. They want to add new a URL to the Intranet Zone, remove the existing URL and change the zone of one of the URLs.

Tasks

  • Get the current AAM settings of the TEAM Web App
  • Remove the URL (http://Port.krossfarm.com) from the custom Zone
  • Add new URL ( http://intra.krossfarm.com ) in the Intranet Zone.
  • Change the Internal URL (http://kfsp:9101 ) from default Zone to Intranet Zone

Get

First, we will run the get command to get the current AAM settings of Team Web. Please run the follow the command.

Get-SPAlternateURL -WebApplication "teamweb"

The output will be like this.

Remove

Now we will remove the http://Port.krossfarm.com from the custom zone of Team Web

Remove-SPAlternateURL -Identity http://port.krossfarm.com
  
Get-SPAlternateURL -WebApplication "teamweb"

You have to confirm it after running the Remove command (as shown in below pic). Above command remove the custom zone URL from AAM.

 

New

Now we will add the new URL (http://intra.krossfarm.com) for the intranet zone. For this, we have to run the new command.

New-SPAlternateURL -WebApplication "teamweb" -Url http://intra.krossfarm.com -Zone intranet
  
Get-SPAlternateURL -WebApplication "teamweb"

This will add the new URL in AAM, see the pic below.

Set

Lastly, we have to change the Internal URL ( http://kfsp:9101) from Default Zone to Intranet Zone. Run the below command

Get-SPAlternateURL http://kfsp:9101 | Set-SPAlternateURL -Zone "intranet"
  
Get-SPAlternateURL -WebApplication "teamweb"

As shown in pic below, you see the Set command change the internal URL from Default Zone to the Intranet Zone.

 

Important

Set-SPAlternateURL command only uses to change the Internal URL, if you try to change the public URL it will throw the following error.

Set-SPAlternateURL : The public Custom zone URL http://port.krossfarm.com cannot be deleted.  Set another URL to be the public Custom zone URL before performing this action.
 
At line:1 char:83
 
+ ... e "custom" } | Set-SPAlternateURL -Zone "Intranet"
 
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
    + CategoryInfo          : InvalidData: (Microsoft.Share...SetAlternateUrl:SPCmdletSetAlternateUrl) [Set-SPAlternateURL], ArgumentException
 
    + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletSetAlternateUrl

Note

This is an example, the situation will vary in your environment. This example is just for learning the purpose and to give you an idea how to use these commands. 

See Also