PowerShell Is Your New XPath Builder in Sitecore 9

Author

Brandon Bruno

Published

November 18, 2017

Tags

PowerShell Is Your New XPath Builder in Sitecore 9

About XPath Builder

Sitecore's XPath Builder is a tool that lets users execute Sitecore and XPath queries right in the Sitecore Client. This was a quick-and-dirty tool - not pretty, but it got the job done and worked for plenty of basic reporting needs and quick query debugging.

XPath Builder in previous versions of Sitecore.

The XPath Builder (and the Developer Center as whole) was already deprecated with Sitecore 8, but it was always accessible if you knew the correct URL:

	
http://<sitecore_instance>/sitecore/shell/default.aspx?xmlcontrol=IDE.XPath.Builder
	

If you rely on XPath Builder for business or technical reasons, Sitecore 9 is going to surprise you. XPath Builder has been removed in Sitecore 9. If you need the same functionality, I recommend two alternatives:

Sitecore Rocks is strictly a developer tool, so it doesn't help if you need query functionality in the Sitecore Client. PowerShell is your best option.

PowerShell to the Rescue

Simplicity was the beauty of the XPath Builder. It had just a few inputs (a query window, context selection, query type) and one output (a list of query results). It only performed read operations against the content tree - no write operations - so it was relatively safe for experimentation.

If you and your users have been using XPath Builder, now is the time to move on to Sitecore PowerShell Extensions (SPE). While SPE is a more complex tool to learn and use, the flexibility it provides to Sitecore is worth the learning curve.

Reproducing the query functionality of the XPath Builder in Sitecore 9 is easy with PowerShell. It's just one line of code:

	
Get-Item -Path master:// -Query "/sitecore/content//*[@@TemplateName = 'Sample Item']"
	

Now SPE begins to really shine, because you can do more than just output a list of query results. Want to output certain fields on these items? Sort by author or by the date each item was created? Find referrer items? Modify the presentation of pages? Have at it.

Queries aren't the only way to get data from the Sitecore content tree in PowerShell. Check out the Sitecore PowerShell Extensions documentation to get started with other options and cmdlets.

Also check out my previous post, Getting Items in Sitecore PowerShell: A Comparison of Options for a quick rundown of how to access tens-of-thousands of items at once in SPE.

Do you have questions, comments, or corrections for this post? Find me on Twitter: @BrandonMBruno