Sitecore – export all users that are in a role

If you’ve ever dug into the security tables of Sitecore you’ll discover its based on the aspnet membership tables which are typically stored in core.

Recently we needed to export all the users that are in a certain role – it turned out it was easier than expected.

The outcome is that when you view the members of a certain role you can now export to a csv.

export-users

There are a few things you need to update to enable the additional ‘Export’ button.

  1. Update the xaml view for the members popup
  2. Patch in the new command
  3. Create a new sitecore command for generating the export

1. Update the xaml view for the members popup

If you navigate to ‘\sitecore\shell\Applications\Security\RoleManager’ and edit ‘ViewMembers.xaml.xml’ you should be able to see 2 buttons – the new one added below:

A tip for tracking down the xaml file in question – if you fire up either fiddler/chrome developer tools/firebug and open up the members panel and have a look at the pages being loaded you should see something like:
request-url
After the ~ you can see /xaml/Sitecore.Shell.Applications.Security.RoleManager.ViewMembers.aspx – this mimics the folder structure with fullstops replaced by folders.

2. Patch in the new command

Using sitecore patch files, create the new command reference

3. Create a new sitecore command for generating the export

Now you just need the code. The example below allows for profile information to be included in the export, simply update the ProfileFields array to include the properties you want. ComputedFields allows you to amalgamate or process other fields to gather more information as needed.

2 thoughts on “Sitecore – export all users that are in a role

  1. Hi there,

    I’m trying to export about 100 users from Sitecore and your blog post is really helpful. However, I am slightly stuck – disclosure: I am a Sitecore novice – and I had a couple of very quick questions. 1. the hashes in the namespace and command name, they should be replaced with what, the name of the website folder in inetpub? 2. Vis Studio is throwing an error with Sitecore.Shell.sitecore.shell.Applications.MarketingAutomation.Utils (and Sitecore.Shell.Applications.MarketingAutomation.Utils), is that the correct using statement? Finally 3. Vis Studio saying CsvExported doesn’t exist in the current context, where can I find it?

    Sorry again if these questions are beyond dumb.

    Paul

    • The ### are simply to mask out the namespaces I used in the project. They could be anything you want but I suspect would want to mimic the pattern you already have.

      The automation tools are in the Sitecore.Shell.MarketingAutomation.dll – have you got that referenced?

Leave a Reply

Your email address will not be published. Required fields are marked *