Forum Discussion
Need help importing user data from csv
- Jun 28, 2022
Hey, Harm.
I'd strongly recommend using the -Filter parameter in the Get-AD* calls, as you're current pulling every single user in Active Directory client-side before filtering anything - twice.
In smaller environments, that won't be an issue, but it'll run into scalability issues rather quickly.
Using your original example, something like this would be more efficient in medium to large directories:
$csv = import-csv c:\scripts\accounts.csv foreach ($line in $csv) { $user = Get-ADUser -Filter "employeeID -eq '$($line.EmployeeID)'"; # Here, we're now leveraging server-side filtering. $manager = Get-ADUser -Filter "employeeID -eq '$($line.SupervisorID)'"; # And again here. if ($user -is [Microsoft.ActiveDirectory.Management.ADUser] -and $manager -is [Microsoft.ActiveDirectory.Management.ADUser]) { # We only want to be in here where we got precisely one user and one manager, otherwise we have no way to arbitrate who gets updated with what. Set-ADUser $user -Manager $manager } }
Cheers,
Lain
**Announcing export-ADData: Open Source Toolkit for Flexible, Robust AD Import & Export (with Practical Resume Support)**
Hello PowerShell Community,
I've often found that when it comes to importing or exporting Active Directory users and groups, the solutions available are either very basic (using `Import-Csv | New-ADUser` for one-off cases), or only available as paid enterprise tools. For real-world migrations, reorganizations, or even large-scale recovery projects, these approaches just don’t offer the flexibility, safety, or control that busy AD admins need.
**That’s why I created [export-ADData](https://github.com/Tatsuya-Nonogaki/export-ADData)**—an open-source PowerShell toolkit that aims to fill this gap. I’m not selling anything, and there’s no catch here: I built these scripts to handle complex AD tasks in my own work, and am sharing them in hopes they’ll help others facing similar challenges.
### What Makes export-ADData Different?
- **Full round-trip support:** Export users and groups (with all attributes) to CSV, and import them back—even across different domains or OU structures.
- **Advanced import features:**
- Cross-domain migration
- OU flattening and reorganization
- Group membership restoration
- Automatic creation of missing OUs
- Flexible mapping and granular container placement
- **Robust validation:** Strong argument checking and error handling help avoid accidental mistakes.
- **Detailed logging:** All actions are logged for accountability and troubleshooting.
- **Safe-to-repeat/practical resume:** The import script never overwrites existing objects. If some records fail (e.g., due to missing groups or prerequisites), you can fix the issues and rerun safely—only missing objects are processed, making staged or partial imports straightforward.
- **Completely free and open source:** No paid edition, no upsells, and no hidden features.
### Why Share Here?
I’ve noticed many questions here about bulk AD import/export, but most answers only cover basic cmdlet usage. There isn’t much available for admins who need to handle complex migrations, mass re-orgs, or recoveries with confidence.
### Limitations and Transparency
- There’s currently no “dry-run” mode; all actions are real, but existing users/groups are never overwritten, which keeps things safe.
- This tool is designed for targeted AD migration and reorganization—not entire forest/domain migrations.
- I’m actively seeking feedback, ideas, and contributions to make it even better.
---
**Repo & Documentation:**
[https://github.com/Tatsuya-Nonogaki/export-ADData](https://github.com/Tatsuya-Nonogaki/export-ADData)
README can be viewed also at:
[export-ADData|GitHub Pages](https://tatsuya-nonogaki.github.io/export-ADData/)
**Thanks for reading! If you have any questions, suggestions, or want to share your experience with similar projects, I’d love to hear from you here or via GitHub.**