Adding a user via PShell in AD UC

Posted on 2014-09-03
Medium Priority
Last Modified: 2014-10-03
I would be very greatfull to anyone who can provide me with a Powershell to do the following.
Add a user to a domains specified OU in AD Users and Computers with the following fields filled in...

First Name:            John  
• Last Name:            Doe
• Job Title:            Manager
• Office Location:      College
• Telephone:            01245-592300
• Street:            Deer Street
• City:            Rhuddlan
• State/Province      Denbighshire
• Zip code:            LL17 5UH
• Fax:                  0345- 91736
• Department      Pengwern College
• Manager : Mr Manager

Anyone that can provide me with this today I will be so greatful for that.

Thanks everyone for the help though
Question by:Jason Laskey
LVL 26

Accepted Solution

Sekar Chinnakannu earned 2000 total points
ID: 40302782
You can add the user using New-ADUser command, refer this MS article for each and every attributes you can get clear details  http://technet.microsoft.com/en-us/library/ee617253.aspx if you are looking for a multiple user at same time the n you need to import the CSV file to perform same action http://pc-addicts.com/powershell-create-multiple-users-ver-2/

Expert Comment

ID: 40302785
I did this very quickly by using "PowerShell ISE" and "Import-Module Active Directory"

What you'd like to achieve looks probably like this
New-ADUser -Name "Doe John" -GivenName "John" -Surname "Doe" -Title "Manager" -Office "College" -OfficePhone "01245-592300" -StreetAddress "Deer Street" -City "Rhuddlan" -State "Denbigshire" -PostalCode "L17 SUH" -Fax "0345-91736" -Department "Pengwern College" -Manager "samAccountName of his managers active directory account" -Path "distinguishedName to the OU you'd like to create the account in"

For next time, i would recommend you to use your browser, then you would have found this article or some other examples.


Expert Comment

ID: 40302788
Something like:
New-ADUser "John Doe" -Path "CN=Users,DC=Domain,DC=local" -Givenname "John" -Surname "Doe" -Title "Manager" -Office "College" -streetAddress "Deer Street" -City "Rhuddlan" -State "Denbighshire" -postalCode "LL17 5UH" -department "Pengwern College" -manager "<FullDN Manager>" -OtherAttributes @{telephoneNumber="01245-592300";facsimileTelephoneNumber="0345-91736"}

More information about this ps command: http://technet.microsoft.com/en-us/library/ee617253.aspx

Also, this doesn't cover login name etc.. That would be UPN or UserPrincipalName
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Author Comment

by:Jason Laskey
ID: 40302939
Sorry I was in a rush as had to dash out thanks for all the comments I will try the CSV option as initially what I would like to do is create the colums in a CVS, send it to the users and they fill it in..then just run a PS script against the *.csv file.
Any better ideas?

Expert Comment

ID: 40303396
I'm working on a web based form that can be used by the human resources team.
The information of the form gets saved in csv format and will be automatically processed.
After the account is created the admin get an email that a new user was created and probably needs some final adjustments.
I will try to automate it as much as possible. Also with adding a mailbox and other properties.

But as you see, its basically the same. Importing a CSV file with PowerShell.

Author Comment

by:Jason Laskey
ID: 40309870
@Sekar Chinnakannu:

Hi Mate OK so I changed the *.ps script to the following:

Import-Csv "NewUsers.csv" | ForEach-Object {
 $userPrinc = $_."Logon Username" + "@domain"
 New-QADUser -Name $_.Name `
 -ParentContainer $_."Container" `
 -SamAccountName $_."Logon Username" `
 -UserPassword "Password01" `
 -FirstName $_."First Name" `
 -LastName $_."Last Name"
 -Description $_."Job Title"
 -PhysicalDeliveryOfficeName $_."Office"
 -TelephoneNumber $_."Telephone Number" ` `
 -StreetAddress $_."Street Address" 
 -l $_."City" `
 -St $_."State/Province" 
 -PostalCode $_."Postal Code"
 -FacsimileTelephoneNumber $_."Fax"
 -Department $_."Department"
 -Title $_."Job Title"
 -Company $_."Company"
 -Manager $_."Manager"
 -CountryCode $_."Country"
 -UserPrincipalName $userPrinc `
 -DisplayName $_."Name" ;`
 Add-QADGroupMember -identity $_."Distribution Group" -Member $_."Logon Username" ;`
 Set-QADUser -identity $_."Logon Username" `
 -UserMustChangePassword $true `

Open in new window

But I get an error when running the ps script something about -Description $_."Job Title" char 3.
Any ideas as this is so frustrating.

Thanks for you assistance though

Author Comment

by:Jason Laskey
ID: 40311804
OK 'Im officially at my whits end and need serious help with this I have done the following and setup the following but keep getting this error
"Missing expression after unary operator '-'.
At line:14 char:2"
Attached is the *.ps file and the Excel Spreasheet
Add-NewUsers.ps1.txt = PS script to run

New-Users.csv= csv to run ps script against

New-Users.xlsx= xlsx sent to users and they must fill in the details

Please help this is urgent been busy with this for a week and have no idea what the error means or where I am going wrong

Author Comment

by:Jason Laskey
ID: 40313915
@Sekar Chinnakannu:

I managed to get it to work but now I have a problem what if there is already a nlastname user and now I want it to say "OK if the user nlastname exists make the username nlastname1. Is this possible?

Author Comment

by:Jason Laskey
ID: 40349368
Eventually after playing around with this and doing some research and once again testing etc I eventually came right with this.
These are some of the resources I had to using and test in order to get to my result

Author Comment

by:Jason Laskey
ID: 40358893
I've requested that this question be closed as follows:

Accepted answer: 500 points for Sekar Chinnakannu's comment #a40302782
Assisted answer: 0 points for Jason Laskey's comment #a40349368

for the following reason:

Eventually after playing around with this and doing some research and once again testing etc I eventually came right with this.
These are some of the resources I had to using and test in order to get to my result
along with  < Sekar Chinnakannu> reccomendation

Author Closing Comment

by:Jason Laskey
ID: 40358894
This is a brilliant How to Site with Video thanks again after eventually playing around with some ideas from this site and then tweaking my own *.ps1 script and my Excel Template, I have managed to accomplish the task at hand. Sorry for the long response as took a while before I was 100% certain

Featured Post

Evaluating UTMs? Here's what you need to know!

Evaluating a UTM appliance and vendor can prove to be an overwhelming exercise.  How can you make sure that you're getting the security that your organization needs without breaking the bank? Check out our UTM Buyer's Guide for more information on what you should be looking for!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
The article explains the process to deploy a Self-Service password reset portal I developed a few years ago. Hopefully, it will prove useful to someone.  Any comments, bug reports etc. are welcome...
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question