Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Importing Users via CSV

Posted on 2013-01-07
2
Medium Priority
?
818 Views
Last Modified: 2013-01-08
Hello,

I'm making a mistake somewhere in the process of reading a CSV containing user records and using the New-ADUser cmdlet to add them to AD.  I'm running these commands on a patched 2008R2 domain controller.

the csv file is as follows (also attached):

Object_Path,Object_Name,name,samaccountname,userprincipalname,givenname,sn,displayname,company,streetaddress,l,st,postalcode,telephonenumber,facsimiletelephonenumber,homephone,mobile,mail,title,department,physicaldeliveryofficename,info,tempPassword
LDAP://TL,TL,testuser7,testuser7,testuser7@structures.com,Test,User,"Test User 7",testuser7,Address,Greenwood Village,CO,80111,303-555-5555,303-555-5555,303-555-5555,303-555-5555,tuser7@redacted.com,Toady,Custodial,Denver,This is a notes field,abc123456@@@

Open in new window


the script is:

Import-Csv .\test_ad_users2.csv
foreach-object {
	#$password = $_.tempPassword
	New-ADUser `
		-SamAccountName $_.SamAccountName `
		-UserPrincipalName $_.userprinicpalname `
		-DisplayName $_.name `
		-Name $_.name `
		-GivenName $_.cn `
		-SurName $_.sn `
		-Department $_.Department `
		-Path "OU=ImportTest,DC=ifs,DC=local" `
		-AccountPassword (ConvertTo-SecureString "abc123456@@@" -AsPlainText -force) `
		-Enabled $True `
		-PasswordNeverExpires $True `
		-PassThru `
		}

Open in new window


I'm getting the error:

New-ADUser : Cannot validate argument on parameter 'Name'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.
At C:\adimport\ADMUserCreation.ps1:10 char:8
+         -Name <<<<  $_.name `
    + CategoryInfo          : InvalidData: (:) [New-ADUser], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.NewADUser

I've tried everything I can think of to understand what this message means in my context.  If I run the following I get the name attribute "testuser7" returned:

import-csv c:\adimport\test_ad_users.csv | foreach-object { $_.name}

Open in new window


that tells me the error isn't what it seems to be.  Anyone have any ideas?  Any help would be appreciated.

Thank you.

Mitch
0
Comment
Question by:mfishco
[X]
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
2 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 2000 total points
ID: 38753300
In your script, you didn't pipe the Import-Csv output to foreach-object. Try..
Import-Csv C:\test_ad_users2.csv | foreach-object  {
	#$password = $_.tempPassword
	New-ADUser `
		-SamAccountName $_.SamAccountName `
		-UserPrincipalName $_.userprincipalname `
		-DisplayName $_.name `
		-Name $_.name `
		-GivenName $_.cn `
		-SurName $_.sn `
		-Department $_.Department `
		-Path "OU=ImportTest,DC=ifs,DC=local" `
		-AccountPassword (ConvertTo-SecureString "abc123456@@@" -AsPlainText -force) `
		-Enabled $True `
		-PasswordNeverExpires $True `
		-PassThru `
		}

Open in new window

0
 

Author Comment

by:mfishco
ID: 38754993
Thank you!  Such a small thing taking so much time and energy...
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

722 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