Reading and saving file taking too long

If you want to do the re-indexing at the same time when you delete address(es) you could do something like this

# Sample data - replace with whatever you have to get your list of users
$Users = @(
    '1=jbruce@company.com',
    '2=oreynolds@company.com',
    '3=JSTACK@company.com',
    '4=Dwu@company.com',
    '5=dsmith@company.com',
    '6=tantony@company.com',
    '7=jason.d@company.com',
    '8=jpettus@company.com',
    '9=plynch@company.com',
    '10=rhowe@company.com',
    '11=cconner@company.com',
    '12=cOberdalhoff@company.com',
    '13=emccomas@company.com',
    '14=fbrisco@company.com',
    '15=rmiller@company.com',
    '16=rburns@company.com',
    '17=jkohler@company.com',
    '18=Kfantom@company.com',
    '19=blevis@company.com',
    '20=test@company.com'
)

# E-mail address(es) to delete from your list
$delete = @(
    'jbruce@company.com',
    'Kfantom@company.com'

)

# Initialize index variable
$new_index = 0

# Loop through all users and filter out those from delete variable
$Users_Filtered = foreach ($User in $Users) {
    $index, $email = $User -split '='
    
    if ($delete -notcontains $email)
    {
        $new_index++
        Write-Output "$new_index=$email"
    }
    
}

# Final filtered list - insert whatever logic you need to save result to file
$Users_Filtered

I would expect that to be rather fast

Ah. OK. What a pitty. I will think about that a little more. Maybe we can streamline it a little.

Likewise to add to your list - assuming it is already ordered, you could do like this

# Sample data - replace with whatever you have to get your list of users
$Users = @(
    '1=jbruce@company.com',
    '2=oreynolds@company.com',
    '3=JSTACK@company.com',
    '4=Dwu@company.com',
    '5=dsmith@company.com',
    '6=tantony@company.com',
    '7=jason.d@company.com',
    '8=jpettus@company.com',
    '9=plynch@company.com',
    '10=rhowe@company.com',
    '11=cconner@company.com',
    '12=cOberdalhoff@company.com',
    '13=emccomas@company.com',
    '14=fbrisco@company.com',
    '15=rmiller@company.com',
    '16=rburns@company.com',
    '17=jkohler@company.com',
    '18=Kfantom@company.com',
    '19=blevis@company.com',
    '20=test@company.com'
)

# E-mail address(es) to add to the list
$add = @(
    'johndoe@company.com',
    'janedoe@company.com'
)

# Initialize index variable
$new_index = $Users.Count

# Loop through addresses and add to list
foreach ($email in $add)
{
    $new_index++
    $Users += "$new_index=$email"
}

# Final list - insert logic to save to file
$Users

tired to seeing as you walk on rake
… you write full ini on each of your 1400 users.

here is my present. I spent 40 minutes but its work in second with 10000 users :slight_smile:
and it can be optimized more if ini group reading will be modified to use collections instead of hashes, because you want renumerations

I will be glad if someone find it useful :slight_smile: