Showing posts with label Managed Path. Show all posts
Showing posts with label Managed Path. Show all posts

Tuesday, 11 February 2014

Create Managed Path using PowerShell

Create Managed Path using PowerShell

$Webappname = Read-Host "Enter web application URL"
#"http://testsite.com"

$mPathEquity = "equity" # manged Path 1
$mPathDebt = "debt" # manged Path 2

function Create-SPManagedPath
{
param ($webApplicationUrl, $managedPathName)
$managedPath = Get-SPManagedPath -WebApplication $webApplicationUrl -Identity $managedPathName -ErrorAction SilentlyContinue
if ($managedPath -ne $null)
{
Write-Host "Managed path $managedPathName already exists."
return
}
Try
{
Write-Host "Creating managed path $managedPathName ..."
New-SPManagedPath –RelativeURL $managedPathName -WebApplication $webApplicationUrl

Write-Host "Managed path $managedPathName created sucessfully" -foregroundcolor Green
}
catch [Exception]
{
Write-Host   $_.Exception.ToString()
}
}

 Write-Host "Creating Managed Paths" -foregroundcolor Yellow
 Create-SPManagedPath  $Webappname $mPathDebt
 Create-SPManagedPath  $Webappname $mPathEquity
 Write-Host "Completed Creating Managed Paths" -foregroundcolor Green