Home > MOSS 2007 > PowerShell: Adding Managed Paths

PowerShell: Adding Managed Paths

October 1st, 2008 Leave a comment Go to comments

Just a quick note to let you, PoSH lovers , know that if you are adding managed paths to an SPWebApplication object using PoSH ,  for adding an SPPrefix object to the existing SPPrefixCollection , you need to specify one of the following arguments (without space), otherwise you get a conversion error  to type “Microsoft.SharePoint.Administration.SPPrefixType” due to invalid enumeration value:

  1. “ExplicitInclusion”
  2. “WildcardInclusion”
  3. “Exclusion”

In the following example, I am creating a sample Web application using the best defaults that SharePoint can determine (Thanks to SPWebApplicationBuilder!).I don’t care about setting any properties for my SPWebApplication. I then go ahead and immediately after the web application is provisioned (appears in IIS as a site) I add a managed path. Again , DO NOT forget to call Update() method on SPWebApplication object to serialize its state and propagate changes throughout your server farm. No different than when you write managed code against the SharePoint object model!

  1. [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
  2. $farm = [microsoft.sharepoint.administration.spfarm]::local
  3. $webAppBuilder = new-object Microsoft.SharePoint.Administration.SPWebApplicationBuilder $farm
  4. Write-Host "The following lines may take up several minutes. . ."
  5. $webApp = $webAppBuilder.Create()
  6. $webApp.Provision()
  7. Write-Host "Addding a managed path with explicit inclusion. . ."
  8. $webApp.Prefixes.Add("DevHorizon","ExplicitInclusion")
  9. $webApp.Update()
  1. No comments yet.
You must be logged in to post a comment.