Solved

Adding a user via PShell in AD UC

Posted on 2014-09-03
12
116 Views
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
0
Comment
Question by:Jason Laskey
12 Comments
 
LVL 25

Accepted Solution

by:
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  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/
0
 
LVL 1

Expert Comment

by:Psymonious
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.

New-ADUser
http://technet.microsoft.com/en-us/library/hh852238.aspx
0
 
LVL 5

Expert Comment

by:bernardbrink
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
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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?
0
 

Author Comment

by:Jason Laskey
ID: 40303350
0
 
LVL 1

Expert Comment

by:Psymonious
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.
0
 

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
0
 

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
Add-NewUsers.ps1.txt
New-Users.csv
New-Users.xlsx
0
 

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?
0
 

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
http://www.morgantechspace.com/2014/04/Create-Bulk-AD-Users-from-CSV-using-Powershell-Script.html
NewEmail.-ActiveSyncDisabled.txt
0
 

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
http://www.morgantechspace.com/2014/04/Create-Bulk-AD-Users-from-CSV-using-Powershell-Script.html,
along with  < Sekar Chinnakannu> reccomendation
0
 

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
0

Featured Post

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.

Question has a verified solution.

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

Resolve DNS query failed errors for Exchange
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
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 …

785 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