I need help, I can already create users with csv, I need to add the created users to groups that a mirror user belongs to. here’s what I’ve done so far. I couldn’t evolve
Before we proceed … please go back, edit your question once again and fix the formatting of your code.
When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
I would strongly advise against mirroring another existing user for group membership to be given to a new employee. Over time users can accumulate membership in groups that may not be appropriate to give to a brand-new employee. This can lead to security problems or simply access to confidential data they should not.
I would encourage rather have a vetted list of groups the new employee needs and feed that into your script by means other than mirroring and existing user.
Agree with @Matt here. Copying existing users is bad practice and risks exposing sensitive data.
If you absolutely must, you could create a (couple of) inactive template user(s) and work from, but I would rather recommend building a role based template instead.
Here’s a thread where a number of those issues are discussed: AD Account Creation
There may be something that can give you some ideas going forward.