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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 25

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
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.


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

WatchGuard's M Series Appliances - Miecom Approved

WatchGuard's newest M series appliances were put to the test by Miercom.  We had great results and outperformed all of our competitors in both stateless and stateful traffic throghput scenarios! Ready to see how your UTM appliance stacked up? Download the Miercom Report!

Question has a verified solution.

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

Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
Group policies can be applied selectively to specific devices with the help of groups. Utilising this, it is possible to phase-in group policies, over a period of time, by randomly adding non-members user or computers at a set interval, to a group f…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

777 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