Tuesday, March 3, 2015

Working with Sitecore Names & Sitecore Powershell

If you're using Sitecore Powershell and have to create a large amount of items you will probably run into issues with allowable names. Sitecore, by default, forbids quite a few special characters (mainly those dealing with HTTP routing -- & for example) and Sitecore admins can further restrict these characters by using the InvalidItemNameChars setting in web.config.

There's a handy way to handle it automatically built into the sitecore API that you can use:

Add-Type -Path "C:\path\to\your\Sitecore.Kernel.dll"
  $fixedName= [Sitecore.Data.Items.ItemUtil]::ProposeValidItemName($originalName)

Just another reminder that in sitecore powershell you aren't limited to just the pre-defined powershell modules, you can add references to the sitecore kernel (or other relevant assemblies) and use the native sitecore API.

No comments:

Post a Comment