We have over 200k users in our sitecore system. I need to export a list of users who meet a certain criteria. I am using a powershell script for this and I am using the get-user command to retrieve the users. I am then looping through the list of users and picking those that meet my criteria; in my case those users who are older than 18. I am then writing the result out to a csv file using export-csv. I find that this is taking over 1.5 hours to complete.
My question is, is there a way I can do a get-user and specify my criteria of age older than 18? The field age is stored in a custom property. Also, any other efficient ways (other than powershell) of accomplishing what I am trying to do here?
Here is the original code:
function export($user)
{
$age = $user.profile.GetCustomProperty("age")
if{$age -gt 18)
{
$id = $user.profile.GetCustomProperty("id")
$firstname = $user.profile.GetCustomProperty("first name")
$user | select-object -property @{Name="First Name";Expression={$firstname}},
@{Name="Age";Expression={$age}},
@{Name="ID";Expression={$id}} |
Export-CSV -Path c:\temp\out.csv -Append -NoTypeInformation
}
}
$users = get-user -Filter *
if($users -ne $null)
{
$users | foreach {export($_)}
}