Hi Friends,
Here I’m again with a new question.
I’m struggling with my script which add new users in bulk. I’ve referred many forum, websites & videos and they all use the exact method which I’m using but I’m getting this error after executing my script.
Here’s the error message which I receive:
New-ADUser : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again..
Below is my script which imports a csv file which have the data for my users and add certain parameters:
=============================================================
The problem is most likely in your CSV. The error is telling you that Name is Mandatory and you are giving it a NULL value. You can investigate like so:
You also have name referenced differently that $.Name, although it shouldn’t matter I would just use $.Name unless you had a space in the header (e.g. $_.“My Name”)
So, I used your method to Test the csv file which you gave… So, the first line get the data properly as I tried looking the info of the variable and it shows the data for all the listed users in the CSV.
PS C:\%FOLDERNAME%> $csv
Name : %STAFFNAME%
samAccountName : %STAFF USERNAME%
Cn : %STAFF FIRSTNAME%
Sn : %STAFF LASTNAME%
EmailAddress : %STAFF EMAIL%
Title : %RELEVANT INFO%
Department : %RELEVANT INFO%
Description : %RELEVANT INFO%
Company : %RELEVANT INFO%
Path : "%DESIRED OU%"
And when I run the out for “$csv | Where{!$_.Name}”, it doesn’t give any output. That is something strange for me.
With regards to the $_.Name thingy, it was just to let you all know that I even tried that.
Are those % values what you are sending? If the query is coming back with nothing, that is the expected results because none of the rows have a NULL value in Name. You should also use splatting over the line continuation:
Seems like path is wrong. Please show us the path, a sample one. Change only the content, please don’t add special character, do like CN=Users, OU=Example1, OU=example2…
Even I did feel that the path is incorrect. So, I changed it & it was back to the initial error which I reported.
With regards tot he special characters, there are none in the path. I edited the output with a % sign, tp avoid publishing sensitive data on the forum.
Possibly, I’ll start from scratch again & see how’s the outcome. Thanks everyone for the inputs.