Adding a user via PShell in AD UC

Posted on 2014-09-03
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 25

Accepted Solution

Sekar Chinnakannu earned 500 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 if you are looking for a multiple user at same time the n you need to import the CSV file to perform same action

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:

Also, this doesn't cover login name etc.. That would be UPN or UserPrincipalName
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.


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?

Author Comment

by:Jason Laskey
ID: 40303350

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

A brief introduction to what I consider to be the best editor for PowerShell.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

820 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