kwizcom banner advertisement

Create or Delete Managed Path in SharePoint using PowerShell

Managed paths in SharePoint enables us to create a uniform navigational structure to group multiple site collections together. SharePoint Managed Paths can be defined using PowerShell or STSADM command line tool. Managed paths are explained in my another article: Managed path in SharePoint

Create Managed Path in SharePoint using PowerShell:

Use New-SPManagedPath cmdlet to create a new managed path in a web application on the SharePoint farm.
New-SPManagedPath -WebApplication "http://sharepoint.company.com" -RelativeURL "teams"
This adds managed path in sharepoint 2013 using PowerShell. By default, the managed path is created as a wildcard inclusion type. You can include the Explicit switch to create a managed path of explicit inclusion type.
New-SPManagedPath –WebApplication "http://sharepoint.company.com" –RelativeURL "/departments/" -Explicit
Create/Delete/Get Managed Paths in SharePoint PowerShell


PowerShell to Delete Managed path in SharePoint:
If you need to delete a managed path from a specific web application: use Remove-SPManagedPath cmdlet.
Remove-SPManagedPath -Identity "Teams" –WebApplication "http://sharepoint.company.com"
Technet Reference for configuring managed paths: https://technet.microsoft.com/en-us/library/cc261845(v=office.15).aspx

Check whether a Particular Managed Path Exists:
PowerShell offers one more cmdlet: Get-SPManagedPath to check the existence of a managed path. Say, for e.g. you may want to check whether a particular managed path exists or not before creating managed path.

Get Existing Managed Paths
Get-SPManagedPath -WebApplication "http://sharepoint.company.com" 
Get-SPManagedPath displays all managed paths for the given web application. Lets check if managed path exists before creating a new managed path:

Create managed path in SharePoint using PowerShell
Lets add managed path in sharepoint 2013 with PowerShell
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

 write-host "Enter the Web Application URL:"
 $WebAppURL=read-host
 write-host "Enter the Managed Path:" 
 $ManagedPath =read-host

 #Check whether the particular managed path exist already
 $ManagedPathExists = Get-SPManagedPath -WebApplication $WebAppURL -Identity $ManagedPath -ErrorAction SilentlyContinue

 if ($ManagedPathExists -eq $null)
 {
    #Go ahead and create the managed path
    New-SPManagedPath –RelativeURL $ManagedPath -WebApplication $WebAppURL
 }
 else
 {
    Write-Host "Managed path $ManagedPath already exists!"
 }
Managed paths created in Central Admin site can be used only in path-based site collections! Not on host-named site collections (HNSC).

 Using STSADM Tool to Add/Remove Managed Path:

These two stsadm command line tool switches available to Add/Remove Managed paths in SharePoint.
  • Stsadm -o AddPath
  • Stsadm -o DeletePath
Syntax: 
AddPath:
stsadm -o addpath -url <managed path URL followed by web app URL> -type <explicitinclusion or wildcardinclusion>
E.g.:
stsadm -o addpath -url http://sharepoint.company.com/teams/ -type wildcardinclusion

Delete managed path in SharePoint using STSADM:
Syntax:
stsadm -o deletepath -url <Managed Path URL with Web App>
E.g.
stsadm -o deletepath -url http://sharepoint.company.com/teams/

Technet Reference:http://technet.microsoft.com/en-us/library/cc263161%28v=office.12%29.aspx

Tail: What if I delete the Managed path in use?
Answer: Your SharePoint Sites under the specific managed path will result: HTTP 404 Page Not Found! Refer my post: SharePoint Managed Paths - FAQs - If you have any questions on SharePoint Managed paths!
Create or Delete Managed Path in SharePoint using PowerShell Create or Delete Managed Path in SharePoint using PowerShell Reviewed by Salaudeen Rajack on December 09, 2012 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.