https://labclient.labondemand.com/LabClient/a5fc4f9c-b9a3-45f2-92eb-5764d14c9954?rc=10

Hi dear all,

I try to create users in my active directory lab using csv file but I always get error message that is beyond my understanding.

Could some one leave me an idea to overcome that issue, please?

Thank you in advance.

Here bellow is attached a shortscreen.

https://labclient.labondemand.com/LabClient/a5fc4f9c-b9a3-45f2-92eb-5764d14c9954?rc=10

without csv file, my script is right and user is created but using csv file, the path always is null or empty (I don’t understand as the path is based distinguished name) or The Account password makes error…

Hi @andre.serville

Can you paste a screenshot of the whole code ListUsers.ps file? Looking at the error in PowerShell I can’t find what specifically is the issue.

Thank you,

Ricardo

Hi Ricardo,
Here is the screenshot of the same issue I perfom on my virtualbox machine:

My csv file is bellow:
First Name;Last Name;Job Title;Office Phone;Email Address;Description;Organizational Unit;Enabled
Mike;Terry;Office Manager;012-345-1232;mike.terry@odvca.org;Ensures excellent physical condition of office;OU=Domain Users,OU=itexpert,DC=itexpert,DC=lab;TRUE
Ridley;Quin;Software Engineer;012-345-1233;ridley.quin@odvca.org;Developps sofware for odvca.org in support of various expansion agenda;OU=Domain Users,OU=itexpert,DC=itexpert,DC=lab;TRUE
Ripley;Dalton;Network Administrator;012-345-1234;ripley.dalton@odvca.org;Administration and security of office network gear and servers;OU=Domain Users,OU=itexpert,DC=itexpert,DC=lab;TRUE
Rollo;Braith;Technical Analist;012-345-1235;rollo.braith@odvca.org;Procures IT sofware and hardware;OU=Domain Users,OU=itexpert,DC=itexpert,DC=lab;TRUE
Stan;Braiden;Support Specialist;012-345-1236;stan.braiden@odvca.org;Provides Tier 2 support to odvca office;OU=Domain Users,OU=itexpert,DC=itexpert,DC=lab;FALSE
Clyde;Cliton;Data Analyst;012-345-1237;clyde.cliton@odvca.org;Provides suggestion based on student and course analytics;OU=Domain Users,OU=itexpert,DC=itexpert,DC=lab;FALSE
Jolyon;Mason;Web Developper II;012-345-1238;jolyon.mason@odvca.org;Works on odvca websites and web apps;OU=Domain Users,OU=itexpert,DC=itexpert,DC=lab;FALSE
Kelsey;Basil;Executive Assistant;012-345-1239;kelsey.basil@odvca.org;Schedules fights, books hotels, car rentals, office parties etc…;OU=Domain Users,OU=itexpert,DC=itexpert,DC=lab;TRUE
Conway;Britton;System Administrator;012-345-1240;conway.britton@odvca.org;Administrates the office servers and VMs;OU=Domain Users,OU=itexpert,DC=itexpert,DC=lab;FALSE
Earnest;Kenzie;Support Specialist;012-345-1241;earnest.kenzie@odvca.org;Procvides Tier 1 support to odvca office;OU=Domain Users,OU=itexpert,DC=itexpert,DC=lab;TRUE

The main problem concerns the path (null or empty) and Accountpassword (unable to convert to secureString and so on …)

Thank you for assistance!

Thank you, I’ll be checking your code.

1 Like

Hey Ricardo,
I found that when I execute my script, the content doesn’t display,except the prompt so I don’t understand why the body of the script is empty.

I erase the script and restart and here is how the pop up of my csv file: the title displays all at the time instead of one by one

I have copied the script on the screenshot and the csv file contents.

This is what I get:

Is that what you were expecting from the script? I see one per line.

Thank you Ricardo
I will retry again based on your advice.
My Hope is to perform automation using powershell and csv file to create user accounts.
I ok revert to you once done.
Thank you again.

Hi @Ricardo,
Coming back to my lab to create users via csv file, I finally get this result. There is always a little failure to create a correct user as mentioned in the below screenshots.

As you can see, the users are created but in the picture 3, there is no UPN in the user profile.

Very tricky

Sorry, I forgot to join my script and the csv file.

I’ll be checking @andre.serville

@ricardo, Here is the screenshot:

Hope this helps to find out my error.
Thank you

Hey @Ricardo,
I ve checked your method with echo, but the command run well but it doesn’t work. No users created.
Bellow is the screenshot.


I refresh the users OU, but no users created.

Try to do an echo this way to check on the parameter’s value:

I am using the same script that I copied from your screenshot and is creating the user in AD.

I was not able to replicate your problem at my local IT Lab. Might be just a typo on the script. Try using a different OU and fewer options just to see if it gets the account created(email, title, description, office phone.

Hi Ricardo,
I am sorry, I built this lab with a French OS.

Coming back to the previous issue I was facing to since a long moment, I completed the UPN like this:

No more changes.
And the user account was completed properly. That improved my satisfaction a little bit.
But there is another error that makes my script not fixed completely.

Finally, despite this error, I was able to create users as followed:

My hope is to run the script without error like Instructor Paul. That could make me happy with the job.

Thank you

I believe the error on the PowerShell script in red relates to the last line of the script which enables the user account ( by looking at the Boolean error). Try to remove that line nd execute it again. It might not have the error.

Hi @ricardo.p

I am trying to create OU automatically in my domain. But, the script doesn’t work as expexted.
So, I cannot perfom step 2 to create a sub-OU or run step 3. And I am looping at the first step (create an OU at the root domain) and ever and ever.
Could you check this scripts for me please?
Thank you.
script_SA

Hi @andre.serville

There is one potential issue with the while loop condition, which always evaluates to true. Replace line 3 with this code and try it to see if it works for you:

while ($choix -notin 1, 2, 3) {

Ricardo

Hi @ricardo,
That leads to the same result.
I can only create an ou under the root domain but not in the sub-domain.
Thank you for your answer.

The logic of switch case 2 has some issues. Check with the following:

$choix=$null
$rootDomain=$(Get-ADDomain).DistinguishedName
While ( $choix -ne (1 -or 2 -or 3)) {
    cls
    Write-Host "Do you want a new OU"
    Write-Host "1)  in the root domain"
    Write-Host "2)  inside an existing OU"
    Write-Host "3)  Exit"
    
    $choix=Read-Host "Answer "
    switch ($choix) {
        1 { 
            $ou=Read-Host "Please enter the name of the new OU:"
            New-ADOrganizationalUnit -Name $ou -Path $rootDomain
        }
        2 { 
            $parent=Read-Host "Please enter the distinguished name of the parent OU:"
            $ou=Read-Host "Please enter the name of the new OU:"
            New-ADOrganizationalUnit -Name $ou -Path $parent
        }
        3 {
            exit
        }
        Default {
            Write-Host "Please choose another option"
            sleep 2
        }
    }
}

Hello @ricardo,
As I told you, I can just create an OU at the root domain but not in the subtree.
I tried to define Parent like the root domain but it doesn’t work.
$Parent = $(Get-ADOU -filter { DistinguishedName -eq “OU=data, dc=data,dc=lab”}).distinguishedname
Hope to perform that idea later.
André