itssemi Posted June 14, 2016 Posted June 14, 2016 Dear all, I am using below script to Create Bulk AD Users from CSV. Filewhich contains set of New AD Users to create with the attributes Name, samAccountName and ParentOU. I want add the first name, last name, display name and groups to the csv file. Can anyone guide me what to change ? Import-Module ActiveDirectory Import-Csv "C:\Scripts\NewUsers.csv" | ForEach-Object { $userPrincinpal = $_."samAccountName" + "@TestDomain.Local" New-ADUser -Name $_.Name ` -Path $_."ParentOU" ` -SamAccountName $_."samAccountName" ` -UserPrincipalName $userPrincinpal ` -AccountPassword (ConvertTo-SecureString "MyPassword123" -AsPlainText -Force) ` -ChangePasswordAtLogon $true ` -Enabled $true Add-ADGroupMember "Domain Admins" $_."samAccountName"; } Thanks
SHimmer45 Posted June 15, 2016 Posted June 15, 2016 for the 1st name and last name add in -givenname & -lastname & -displayname (also adding the variable name from the csv) havent used add-adgroupmember myself but i wouldnt have thought the variable name needs to be in comma's? my powershell foo is rather week however. this might be useful https://technet.microsoft.com/en-gb/library/ee617210.aspx
SHimmer45 Posted June 15, 2016 Posted June 15, 2016 Import-Csv CSV LOCATION PATH | Foreach-object { New-ADUser -Name $_.DisplayName -UserPrincipalName $_.UserPrincipalName -SamAccountName $_.Username -GivenName $_.GivenName -DisplayName $_.DisplayName -Surname $_.Surname -Description $_.Description -Path $_.Path -ScriptPath $_.ScriptPath -HomeDirectory $_.Homedirectory -HomeDrive $_.HomeDrive -AccountPassword (ConvertTo-SecureString $_.Password -AsPlainText -Force) -Enabled $True -PasswordNeverExpires $False -ChangePasswordAtLogon $True -PassThru } example of what i use to import users with currently
SHimmer45 Posted June 15, 2016 Posted June 15, 2016 here are the headers that i use on my CSV file Username,GivenName,Surname,DisplayName,UserPrincipalName,Password,Description,Homedirectory,HomeDrive,ScriptPath,Path this gives me a user with populated fields for username Given Name (1st name) surname display name the UPN password Description Home Dir & Home Dir details and the OU path 1
mani247 Posted June 22, 2016 Posted June 22, 2016 I am just doing the same at my school and this thread has been really helpful. My powershell script works fine, but the problem that I have is that the users home folder is not created, is there another command that needs to be run to create the home folder and set permissions? Thanks
SHimmer45 Posted June 22, 2016 Posted June 22, 2016 the script wont actually create the home folder it just adds the path into the users AD settings. for creating users directories i have another batch script (using md net share & icalcs) its a little old hat but works as i havent got round to looking at a powershell based alternative.
pcstru Posted June 22, 2016 Posted June 22, 2016 There is a script here which may help with creating folders. 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now