Sitecore powershell get-user command -


we have on 200k users in our sitecore system. need export list of users meet criteria. using powershell script , using get-user command retrieve users. looping through list of users , picking meet criteria; in case users older 18. writing result out csv file using export-csv. find taking on 1.5 hours complete.

my question is, there way can get-user , specify criteria of age older 18? field age stored in custom property. also, other efficient ways (other powershell) of accomplishing trying here?

here 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($_)} } 

update:

based on example can see why takes long. exporting csv every iteration.

try this:

$users = get-user -filter * | where-object { $_.profile.getcustomproperty("age") -gt 18 }   $property = @(     "name",     @{name="first name";expression={$psitem.profile.getcustomproperty("first name")}},      @{name="age";expression={$psitem.profile.getcustomproperty("age")}},      @{name="id";expression={$psitem.profile.getcustomproperty("id")}} ) $users | select-object -property $property | export-csv -path c:\temp\out.csv -append -notypeinformation 

old comments:

the more @ i'm doubting can done. age property should serialized , stored on profile. unless there faster way extract profile date, i'm not sure of else can done speed things up.

i suspect doing this:

get-user -filter * | where-object { $_.profile.getcustomproperty("age") -gt 18 } 

i don't know faster way this.


Comments