Get an exportable list of users in Sitecore using Sitecore Powershell


February 09, 2021

Recently I got tasked with exporting a list of all users in a clients Sitecore installation. My immidiate though was to use Sitecore Powershell as I could write the code quick and easy without having to deploy code to their production environment.

For my first attempt I used the function Get-User -Filter * which gives a list of users in Sitecore. The properties of these users are quite limited however and I didn't find an easy way to get properties like email and comments from them.

Name            : sitecore\adminUser
Domain          : sitecore
IsAdministrator : True
IsAuthenticated : False
IsEnabled       : True

After quite a lot of Googling I found the command [System.Web.Security.Membership]::GetAllUsers() which get another list of users. This list contains almost all the properties I could wish for. It was however missing properties for knowing if the user was administrator or which groups it has.

Comment                 : Is Admin
CreationDate            : 5/23/2018 2:02:45 PM
Email                   :
InnerUser               : sitecore\adminUser
IsApproved              : True
IsLockedOut             : False
LastActivityDate        : 2/9/2021 9:28:32 AM
LastLockoutDate         : 1/1/1754 12:00:00 AM
LastLoginDate           : 2/9/2021 9:27:55 AM
LastPasswordChangedDate : 5/23/2018 2:02:45 PM
PasswordQuestion        :
ProviderName            : sitecore
ProviderUserKey         : 11111111-1111-1111-1111-111111111111
UserName                : sitecore\adminUser
IsOnline                : False

The solution was then to combine the two. I choose the way of fetching the users with the [System.Web.Security.Membership]::GetAllUsers() command, and then iterating over them and then getting the user from the Get-User -Id $user.UserName command and expanding the user object with the properties I needed from that.

The final script looks like this:

$userList = [System.Web.Security.Membership]::GetAllUsers()
foreach($user in $userList) {
    $euser = Get-User -Id $user.UserName
    Add-Member -InputObject $user -MemberType NoteProperty -Name "IsAdministrator" -Value $euser.IsAdministrator
$users = $userList | Select-Object -Property @{Label="Email"; Expression={$_.Email} },
    @{Label="Is admin"; Expression={$_.IsAdministrator} },
    @{Label="Username"; Expression={$_.UserName} },
    @{Label="Comment"; Expression={$_.Comment} },
    @{Label="Last logged in"; Expression={$_.LastLoginDate} }

$props = @{
    Title = "Export user data"
    InfoTitle = "$($users.Count) users"
    InfoDescription = "Export user data"
    PageSize = 200
$users | Show-ListView @props

It renders as listview in Sitecore Powershell, in this the records can be sorted by the different columns and then exported to a variety of formats.

List of users