I have an INI file with about 1400 email address. How can I make this read faster? Currently it takes about 3 minutes to read and save file.
I understand the reason why it’s taking a long time is because it’s looping through 1400 times doing the same thing over again. But, what’s a better and faster way to do this? Is there a way to get the values of $Index outside of the for loop?
$Users is the list of email addresses ~ 1400 emails.
Powershell is great for repetitive tasks. So it already know how about to iterate through a collection of items. This might push you in a better direction:
Foreach($User in $Users){
… do something with $User
}
What do you actually want to do with your email addresses?
Thank you, but the numbers of emails could change. It won't be always 1400.
The numbers in front of your email addresses or the amount of email addresses in your file?? You confuse me a little bit. The amount does not matter. The foreach loop iterates over ALL items you have in a list or an array.
Any way to make it dynamic or is for loop the best option in my case?
Hhhhmmm I still didn’t really get what you have to do with your email addresses.
The problem is that (same as the for loop problem) every time I add or delete an email address it reindexes the numbers starting from the beginning to end.
I think the “fastest” way to do this is when I add someone, add them to the very last line, and when I delete someone, reindex the list after the delete email address instead of the whole email list.
The only problem I see with this is that I need to create two functions? One for add and one for delete? The current functions works for both add and delete.
OK. I will only ask this one last time. What do you need to do wiht this email addresses. I believe I could help you if you’d tell me what you need. What is the situation before and what do you expect to be the situation after your script?
is it’s now running about 1 minute faster. Old way I had that inside the foreach, but by putting it outside the foreach, it’s running more faster. Anything I can do?
The reason why I’m writing this script is because there’s a GUI program, but doing it through the GUI takes 5 minutes to create and delete an email, so this is far more faster.
This should do it in seconds.
To write this $NewList to a file you can pipe it to Out-File. Even to the original file if you want.
How do you delete items or add items? Manually in an editor?
How do you think about changing your flat text list to a csv file. You could have one row with the index and one row with the email. I think it would make it easier to maintain and to work with.