Bill Baer /bɛːr/

Skip to main content


Bill Baer /bɛːr/
Bill Baer is a Senior Product Manager for Microsoft 365 at Microsoft in Redmond, Washington.

Alternate Access Mappings and Windows Powershell

Alternate Access Mappings and Windows Powershell

Alternate Access Mappings and Windows Powershell

  Code Samples Windows Powershell

I had a request this week on how to leverage Windows Powershell to add Alternate Access Mappings to the collection for a specific Web application.  Surprisingly after some searching I was unable to find anything existing on the topic, so for those curious see the attached script and corresponding source Xml.


  1. Copy the source below into somefile.ps1.
  2. Copy the Xml source in AAM.xml.
  3. In the Windows Powershell console call ./somefile.ps1.


# Function:    main

# Description:    Main entry point for the script.  Loads the configuration source
#        Xml and initializes the foreach loop to iterate over a
#         collection of Xml nodes.

# Parameters:    None

function main()
  [xml]$cfg = Get-Content .AAM.xml

  if( $? -eq $false ) {
    Write-Host “Cannot load configuration source Xml $cfg.”
    return $false

  $cfg.Configuration.WebApplication | ForEach-Object {
    new-SPAlternateUrl( $_ )

# Function:     New-SPAlternateURL

# Description:     This script adds the specified URLs to the collection of
#        alternate request URLs for the Web application.

# Parameters:    None

function New-SPAlternateURL( [object] $cfg )

  $webApp = $nul;
  $webApp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($cfg.Url)
  trap [Exception] { 
    Write-Error $(“Exception: " + $_.Exception.Message);

  $cfg.AlternateUrl | ForEach-Object {
  $map=New-Object Microsoft.SharePoint.Administration.SPAlternateUrl($_.IncomingUrl, $_.UrlZone)
  return $map


Source Xml

| | Permalink to this article
Fingerprint for this article77276a8df185bfc0d3273fa42fc6f711


Skip to footer

Social Links