NewADUser
This script can create a new user from scratch, or copy an existing user for their permissions.
It's designed to be error tolerant in mind and will proceed when possible.
Example:
- Errors occurring due to a permission issue, will output the error in an easy to read format and provide recommendations
- If an attribute doesn't exist within Active Directory (like mailNickname) is will continue the user creation process and report that is was missing both at the time and at the end of the creation process. (as seen below)
Notes:
- 'User must change password at next logon' is set to true by default.
- Script will check if AD has more than one domain and ask you to select one before proceeding.
New user output example:
================ AD User Management ================
1: Create new user
2: Copy existing user
Q: Quit
========================================
Please make a selection: 1
Enter first name: Test
Enter last name: User
Enter username (leave blank to auto-generate): test.user
Enter OU distinguished name (e.g., OU=Users,DC=domain,DC=com) or leave blank for default:
Using default Users container: CN=Users,DC=ad,DC=domain
Creating user with basic attributes...
SUCCESS: User verified with DN: CN=Test User,CN=Users,DC=ad,DC=domain
Setting email attributes...
Warning: Could not set mailNickname - The specified directory service attribute or value does not exist
Parameter name: mailNickname
Successfully set proxyAddresses: SMTP:test.user@domain.com
Final User Details:
Name : Test User
SamAccountName : test.user
UserPrincipalName : test.user@domain.com
mailNickname : {}
proxyAddresses : {SMTP:test.user@domain.com}
EmailAddress : test.user@domain.com
DistinguishedName : CN=Test User,CN=Users,DC=ad,DC=domain
Enabled : True
Attribute Setting Errors:
- mailNickname: The specified directory service attribute or value does not exist
Parameter name: mailNickname
Add user to groups? (Y/N): y
Enter group names (comma separated): Administrators
Added to Administrators successfully
Script completed. Press Enter to continue...
Copy user output example:
================ AD User Management ================
1: Create new user
2: Copy existing user
Q: Quit
========================================
Please make a selection: 2
Enter username to copy: test.user
Copying from: Test User
Current location: CN=Test User,CN=Users,DC=ad,DC=domain
First name [Test]: John
Last name [User]: Doe
New username (blank to auto-generate): john.doe
Use source OU? [CN=Users,DC=ad,DC=domain] (Y/N): y
Validated target OU: CN=Users,DC=ad,DC=domain
Creating user with basic attributes...
SUCCESS: User verified with DN: CN=John Doe,CN=Users,DC=ad,DC=domain
Setting email attributes...
Warning: Could not set mailNickname - The specified directory service attribute or value does not exist
Parameter name: mailNickname
Successfully set proxyAddresses: SMTP:john.doe@domain.com
Final User Details:
Name : John Doe
SamAccountName : john.doe
UserPrincipalName : john.doe@domain.com
mailNickname : {}
proxyAddresses : {SMTP:john.doe@domain.com}
EmailAddress : john.doe@domain.com
DistinguishedName : CN=John Doe,CN=Users,DC=ad,DC=domain
Enabled : True
Attribute Setting Errors:
- mailNickname: The specified directory service attribute or value does not exist
Parameter name: mailNickname
Copy group memberships? (Y/N): y
Added to Administrators
Script completed. Press Enter to continue...
Languages
PowerShell
100%