How can I optimize my PowerShell – LDAP Query?

Question:

I have created a script that reads from a CSV (or other dataset, but not posting that side) and creates users in my AD environment.

Basically, whatever dataset is passed into the script will be processed, and then a user will be created if they do not exist. If the user exists in the AD already, then the script skips over the entry. This is a CREATE only script.

It’s pretty slow, and I’d like to improve the performance whilst keeping the functionality. Can you give me any tips as to how I can make this perform better?

Thank you in advance for any help you can offer.

Answer:

Try the static Exists() method to find if the user exists in the Students OU:

The $usersOU value is static so you can take it out, place it before the import-csv command.

Source:

How can I optimize my PowerShell – LDAP Query? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply