Have this script
Import-Csv "c:\newuserscopy.csv" | ForEach-Object {
$userPrinc = $_."SamAccountName" + "@mydomainco.uk"
New-QADUser -Name $_."Name" `
-ParentContainer $_."Path" `
-SamAccountName $_."SamAccountName" `
-UserPassword "Today01" `
-FirstName $_."FirstName" `
-LastName $_."LastName" `
-City $_."City" `
-LogonScript "login.bat" `
-Title $_."Title" `
-PostalCode $_."PostalCode" `
-HomeDirectory $_."HomeDirectory" `
-HomeDrive $_."M:" `
-StateOrProvince $_."StateOrProvince" `
-UserPrincipalName $userPrinc `
-DisplayName $_."Name" ;`
}
Only thing is the PostalCode and LastName do not get added to the account for some reason. Can any one spot what I am doing wrong? Everything else fits just not that...
CSV:
Name,DisplayName,FirstName,LastName ,SamAccountName,Path,City,LogonScript,HomeDirectory,HomeDrive,Title,StateOrProvince,PostalCode ,LogonName,UserPrincipalName NTEST,Niel DTEST,NDTEST,test,ND999,"OU=City,OU=Localtion,DC=DOMAIN,DC=co,DC=uk",London,login.bat,\fileshare\nd999,M:,TEST IT Support,local,n1ao1,ND999,[email protected]
Thanks
If your CSV data is an exact copy/paste then the label of the "Last Name" and "Postal Code" fields have a trailing space so the field name is actually "Last Name " and "Postal Code " not "Last Name" and "Postal Code" like it is referred to in the script. Fix those and the data should fill in properly.
Other things that might be wrong are
-HomeDrive $_."M:" `
probably should be -HomeDrive "M:" `
and -UserPrincipalName $userPrinc `
probably should be -UserPrincipalName $_."UserPrincipalName" `