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