Tuesday, May 23, 2017

Exporting the username and custom properties from Sitecore using Powershell

I found a great article on exporting users from Sitecore and it did 90% of what I needed. It showed how to export the custom properties but what was missing was the username.  Read the article for more details on how the export works as it is a really good article.

I am simply going to give you the additional field in bold below as this will give you the username in the form {domain}\{user} eg. sitecore\admin:

$property = @(
@{Name='Email';Expression={ $PSItem.Profile.GetCustomProperty('Email') }},
@{Name='FirstName';Expression={ $PSItem.Profile.GetCustomProperty('FirstName') }},
@{Name='LastName';Expression={ $PSItem.Profile.GetCustomProperty('LastName') }},
@{Name='Title';Expression={ $PSItem.Profile.GetCustomProperty('Title') }},
@{Name='Company';Expression={ $PSItem.Profile.GetCustomProperty('Company') }},
@{Name='Country';Expression={ $PSItem.Profile.GetCustomProperty('Country') }},
@{Name='ZipCode';Expression={ $PSItem.Profile.GetCustomProperty('ZipCode') }},
@{Name='Department';Expression={ $PSItem.Profile.GetCustomProperty('Department') }},
@{Name='Street';Expression={ $PSItem.Profile.GetCustomProperty('Street') }},
@{Name='City';Expression={ $PSItem.Profile.GetCustomProperty('City') }},
@{Name='Phone';Expression={ $PSItem.Profile.GetCustomProperty('Phone') }},
@{Name='Username';Expression={ $PSItem.Profile.GetCustomProperty('Username') }},

# Gets not disabled extranet users, next select all custome properties and save all properties to CSV file
Get-User -Filter 'extranet\*'  `
    | Where-Object { $_.Profile.State -ne 'Disabled' } `
        |  Select-Object -Property $property `
            | Export-CSV -Path "$apppath\extranet-enabled-uc.csv" -notype -encoding "unicode"
Download-File  "$apppath\extranet-enabled-uc.csv"

Hopefully you will find this helpful. Thanks Robert Senktas for the article it helped get me 90% there. If you have tips tricks or resources you would like to share please let me know and I will post them here.

No comments:

Post a Comment