Mapping a Publication to a web application using PowerShell

You can map Publications to web applications within the Content Manager Explorer user interface, and this is the method we recommend. With the required access, however, you can also do this using a PowerShell cmdlet.

About this task

To run PowerShell scripts for software, you require a machine that meets the following requirements:
PowerShell
You require Microsoft Windows PowerShell 5.1. You can download Microsoft Windows Management Framework 5.1, which includes Microsoft Windows PowerShell 5.1, from this location: http://aka.ms/wmf5download
Operating system
You require an operating system that supports both the required PowerShell software and any software for the database you intend to install. As a general rule, ensure that the latest (security) updates are installed on your operating system.
Microsoft .NET Framework
You require a .NET Framework version. The one to use depends on your Windows Server operating system version:
Security
You need to be logged in as a user with sufficient security clearance. For example, to run a script that installs a database, you must be logged in as a user with rights to create that database.

Procedure

Create a mapping from each web application to its corresponding Publication in Content Manager by running the following command (once for each mapping):
Add-TtmMapping -Id MAPPINGID -CmEnvironmentId CMENVIRONMENTID 
   -PublicationID "tcm:X-Y-Z" -WebApplicationId WEBAPPID -RelativeUrl RELURL
where:
  • MAPPINGID is a unique ID for this mapping, for example, StagingMicrosite01Mapping.
  • CMENVIRONMENTID is the unique ID of this (possibly scaled-out) Content Manager instance. Set this to the value of the environment variable called TRIDION_CM_ENVIRONMENT_ID on any Content Manager server machine.
  • tcm:X-Y-Z is the Content Manager URI of the Publication to which you are mapping, that is, the Publication that contains the content for this specific web application, for example, "tcm:0-1-1".
  • WEBAPPID is the unique ID of the web application you are mapping to, for example, StagingMicrosite01. If you are mapping to the default web application of a website with an ID Example, the ID of the web application to specify here for WEBAPPID would be Example_RootWebApp.
  • RELURL is the relative URL from the web application context to the mapped location. If the mapped location is the root, omit this parameter.