# Need Assistance

**URL:** <https://forums.powershell.org/t/need-assistance/23977>\
**Category:** PowerShell Help\
**Created:** [April 19, 2024, 7:31am UTC](https://forums.powershell.org/t/need-assistance/23977 "2024-04-19T07:31:56Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![olivermoris2210](https://avatars.discourse-cdn.com/v4/letter/o/fbc32d/32.png) [@olivermoris2210](https://forums.powershell.org/u/olivermoris2210)\
**Post date:** [April 19, 2024, 7:31am UTC](https://forums.powershell.org/t/need-assistance/23977/1 "2024-04-19T07:31:56Z")

</div>

Hi Everyone,

I have tried to export AD users list ( from csv file ) but I’m getting the below error , anyone can advise me right path,.

**– Failed to create user VISHNUSOMAN - The object cannot be added because the parent is not on the list of possible superiors –**

regards

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [April 19, 2024, 8:46am UTC](https://forums.powershell.org/t/need-assistance/23977/2 "2024-04-19T08:46:19Z")

</div>

Oliver,  
Welcome to the forum. 👋🏼

99 % of the users coming here are needing assistance. So the subject of your question should give a hint about what your question will be. ☝🏼

You may change the category of your question as well. It looks more like you’re asking for “PowerShell Help”. 😉

> [@olivermoris2210](#):
>
> I have tried to export AD users list ( from csv file ) but I’m getting the below error

> [@olivermoris2210](#):
>
> – Failed to create user

Do you _create_ users while exporting a list of them? 🤔

> [@olivermoris2210](#):
>
> anyone can advise me right path,

In general:

- Please provide the code you used (formatted as code please).
- Please provide the complete error message (formatted as code please)

---

<div class="post-metadata">

**Author:** ![olivermoris2210](https://avatars.discourse-cdn.com/v4/letter/o/fbc32d/32.png) [@olivermoris2210](https://forums.powershell.org/u/olivermoris2210)\
**Post date:** [April 19, 2024, 8:56am UTC](https://forums.powershell.org/t/need-assistance/23977/3 "2024-04-19T08:56:14Z")

</div>

here is the error

Failed to create user VISHNUSOMAN - The object cannot be added because the parent is not on the list of possible superiors

PS Script

\<#  
.SYNOPSIS  
Add-NewUsers.ps1

```
.DESCRIPTION
Create Active Directory users from CSV file.

.LINK
alitajran.com/create-active-directory-users-from-csv-with-powershell

.NOTES
Written by: ALI TAJRAN
Website: alitajran.com
LinkedIn: linkedin.com/in/alitajran

.CHANGELOG
V1.00, 03/12/2020 - Initial version
V2.00, 02/07/2024 - Added try/catch and changed to splatting

```

#\>

# Import active directory module for running AD cmdlets

Import-Module ActiveDirectory

# Store the data from NewUsersFinal.csv in the $ADUsers variable

$ADUsers = Import-Csv “C:\temp\NewUsersFinal.csv” -Delimiter “,”

# Define UPN

$UPN = “[millenniumhotels.com](http://millenniumhotels.com)”

# Loop through each row containing user details in the CSV file

foreach ($User in $ADUsers) {  
try {  
# Define the parameters using a hashtable  
$UserParams = @{  
SamAccountName = $User.username  
UserPrincipalName = “$($User.username)@$UPN”  
Name = “$($User.firstname) $($User.lastname)”  
GivenName = $User.firstname  
Surname = $User.lastname  
Initial = $User.initials  
Enabled = $True  
DisplayName = “$($User.firstname) $($User.lastname)”  
Path = $User.ou #This field refers to the OU the user account is to be created in  
City = $User.city  
PostalCode = $User.zipcode  
Country = $User.country  
Company = $User.company  
State = $User.state  
StreetAddress = $User.streetaddress  
OfficePhone = $User.telephone  
EmailAddress = $User.email  
Title = $User.jobtitle  
Department = $User.department  
AccountPassword = (ConvertTo-secureString $User.password -AsPlainText -Force)  
ChangePasswordAtLogon = $True  
}

```
    # Check to see if the user already exists in AD
    if (Get-ADUser -Filter "SamAccountName -eq '$($User.username)'") {

        # Give a warning if user exists
        Write-Host "A user with username $($User.username) already exists in Active Directory." -ForegroundColor Yellow
    }
    else {
        # User does not exist then proceed to create the new user account
        # Account will be created in the OU provided by the $User.ou variable read from the CSV file
        New-ADUser @UserParams

        # If user is created, show message.
        Write-Host "The user $($User.username) is created." -ForegroundColor Green
    }
}
catch {
    # Handle any errors that occur during account creation
    Write-Host "Failed to create user $($User.username) - $_" -ForegroundColor Red
}

```

}

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [April 19, 2024, 8:57am UTC](https://forums.powershell.org/t/need-assistance/23977/4 "2024-04-19T08:57:41Z")

</div>

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( \</\> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

[How to format code in PowerShell.org](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/b/bee50c628238f2c076c0504efb6b15f2fb11f002.gif) 1 \<---- Click 👆🏽 😉

( !! Sometimes the _preformatted text_ button hides behind the settings gear symbol. 😉 )

Please go back, edit your post once again and fix the formatting of your code and error mesages.

---

<div class="post-metadata">

**Author:** ![olivermoris2210](https://avatars.discourse-cdn.com/v4/letter/o/fbc32d/32.png) [@olivermoris2210](https://forums.powershell.org/u/olivermoris2210)\
**Post date:** [April 19, 2024, 9:11am UTC](https://forums.powershell.org/t/need-assistance/23977/5 "2024-04-19T09:11:06Z")

</div>

i have tried with new Topic window… but it’s remain same

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [April 19, 2024, 9:16am UTC](https://forums.powershell.org/t/need-assistance/23977/6 "2024-04-19T09:16:46Z")

</div>

> [@olivermoris2210](#):
>
> i have tried with new Topic window

?? What do you mean?

---

<div class="post-metadata">

**Author:** ![olivermoris2210](https://avatars.discourse-cdn.com/v4/letter/o/fbc32d/32.png) [@olivermoris2210](https://forums.powershell.org/u/olivermoris2210)\
**Post date:** [April 19, 2024, 9:22am UTC](https://forums.powershell.org/t/need-assistance/23977/7 "2024-04-19T09:22:32Z")

</div>

i have tried with new Topic window , but there it’s appearing the same … no difference…

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [April 19, 2024, 10:01am UTC](https://forums.powershell.org/t/need-assistance/23977/8 "2024-04-19T10:01:22Z")

</div>

Are you talking about the formatting? Please carefully (re-) read the explanation I posted. You don’t need a new topic. You may try a **new reply** to this thread instead.

---

<div class="post-metadata">

**Author:** ![olivermoris2210](https://avatars.discourse-cdn.com/v4/letter/o/fbc32d/32.png) [@olivermoris2210](https://forums.powershell.org/u/olivermoris2210)\
**Post date:** [April 19, 2024, 10:17am UTC](https://forums.powershell.org/t/need-assistance/23977/9 "2024-04-19T10:17:37Z")

</div>

\<#  
.SYNOPSIS  
Add-NewUsers.ps1

```
.DESCRIPTION
Create Active Directory users from CSV file.

.LINK
alitajran.com/create-active-directory-users-from-csv-with-powershell

.NOTES
Written by: ALI TAJRAN
Website: alitajran.com
LinkedIn: linkedin.com/in/alitajran

.CHANGELOG
V1.00, 03/12/2020 - Initial version
V2.00, 02/07/2024 - Added try/catch and changed to splatting

```

#\>

# Import active directory module for running AD cmdlets

Import-Module ActiveDirectory

# Store the data from NewUsersFinal.csv in the $ADUsers variable

$ADUsers = Import-Csv “C:\temp\NewUsersFinal.csv” -Delimiter “;”

# Define UPN

$UPN = “[exoip.com](http://exoip.com)”

# Loop through each row containing user details in the CSV file

foreach ($User in $ADUsers) {  
try {  
# Define the parameters using a hashtable  
$UserParams = @{  
SamAccountName = $User.username  
UserPrincipalName = “$($User.username)@$UPN”  
Name = “$($User.firstname) $($User.lastname)”  
GivenName = $User.firstname  
Surname = $User.lastname  
Initial = $User.initials  
Enabled = $True  
DisplayName = “$($User.firstname) $($User.lastname)”  
Path = $User.ou #This field refers to the OU the user account is to be created in  
City = $User.city  
PostalCode = $User.zipcode  
Country = $User.country  
Company = $User.company  
State = $User.state  
StreetAddress = $User.streetaddress  
OfficePhone = $User.telephone  
EmailAddress = $User.email  
Title = $User.jobtitle  
Department = $User.department  
AccountPassword = (ConvertTo-secureString $User.password -AsPlainText -Force)  
ChangePasswordAtLogon = $True  
}

```
    # Check to see if the user already exists in AD
    if (Get-ADUser -Filter "SamAccountName -eq '$($User.username)'") {

        # Give a warning if user exists
        Write-Host "A user with username $($User.username) already exists in Active Directory." -ForegroundColor Yellow
    }
    else {
        # User does not exist then proceed to create the new user account
        # Account will be created in the OU provided by the $User.ou variable read from the CSV file
        New-ADUser @UserParams

        # If user is created, show message.
        Write-Host "The user $($User.username) is created." -ForegroundColor Green
    }
}
catch {
    # Handle any errors that occur during account creation
    Write-Host "Failed to create user $($User.username) - $_" -ForegroundColor Red
}

```

}`Preformatted text`

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [April 19, 2024, 10:42am UTC](https://forums.powershell.org/t/need-assistance/23977/10 "2024-04-19T10:42:47Z")

</div>

I don’t know anymore what to say. 🤷🏼‍♂️

---

<div class="post-metadata">

**Author:** ![grey0ut](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/grey0ut/32/5310_2.png) [@grey0ut](https://forums.powershell.org/u/grey0ut)\
**Post date:** [April 19, 2024, 2:38pm UTC](https://forums.powershell.org/t/need-assistance/23977/11 "2024-04-19T14:38:49Z")

</div>

@Olaf instructions were pretty straight forward. For the sake of moving this along, I’ve formatted the code so it’s readable here:

```auto
<#
.SYNOPSIS
Add-NewUsers.ps1

.DESCRIPTION
Create Active Directory users from CSV file.

.LINK
alitajran.com/create-active-directory-users-from-csv-with-powershell

.NOTES
Written by: ALI TAJRAN
Website: alitajran.com
LinkedIn: linkedin.com/in/alitajran

.CHANGELOG
V1.00, 03/12/2020 - Initial version
V2.00, 02/07/2024 - Added try/catch and changed to splatting

#>
#Import active directory module for running AD cmdlets

Import-Module ActiveDirectory
#Store the data from NewUsersFinal.csv in the $ADUsers variable

$ADUsers = Import-Csv "C:\temp\NewUsersFinal.csv" -Delimiter ","
#Define UPN

$UPN = "millenniumhotels.com"
#Loop through each row containing user details in the CSV file

foreach ($User in $ADUsers) {
    try {
        # Define the parameters using a hashtable
        $UserParams = @{
            SamAccountName = $User.username
            UserPrincipalName = "$($User.username)@$UPN"
            Name = "$($User.firstname) $($User.lastname)"
            GivenName = $User.firstname
            Surname = $User.lastname
            Initial = $User.initials
            Enabled = $True
            DisplayName = "$($User.firstname) $($User.lastname)"
            Path = $User.ou #This field refers to the OU the user account is to be created in
            City = $User.city
            PostalCode = $User.zipcode
            Country = $User.country
            Company = $User.company
            State = $User.state
            StreetAddress = $User.streetaddress
            OfficePhone = $User.telephone
            EmailAddress = $User.email
            Title = $User.jobtitle
            Department = $User.department
            AccountPassword = (ConvertTo-secureString $User.password -AsPlainText -Force)
            ChangePasswordAtLogon = $True
        }

        # Check to see if the user already exists in AD
        if (Get-ADUser -Filter "SamAccountName -eq '$($User.username)'") {

            # Give a warning if user exists
            Write-Host "A user with username $($User.username) already exists in Active Directory." -ForegroundColor Yellow
        }
        else {
            # User does not exist then proceed to create the new user account
            # Account will be created in the OU provided by the $User.ou variable read from the CSV file
            New-ADUser @UserParams

            # If user is created, show message.
            Write-Host "The user $($User.username) is created." -ForegroundColor Green
        }
    } catch {
        # Handle any errors that occur during account creation
        Write-Host "Failed to create user $($User.username) - $_" -ForegroundColor Red
    }

}

```

For the most part this looks fine, though I would change your check if the user already exists to this:

```auto
if (Get-ADUser -Identity $($User.username)) {  
#...  

```

There’s no reason to filter for the specific user when you can user the Identity parameter and be specific.

Past that, from Google searching your error text there are plenty of mentions of that error. The most likely culprit is the specification of the OU to create the user in. [This post](https://adamsync.wordpress.com/2012/06/22/structure-rules-naming_violation-and-error-0x2099-the-object-cannot-be-added-because-the-parent-is-not-on-the-list-of-possible-superiors/) illustrates an example of that.  
Since you know the user that the error happened on, open your CSV, find your row for “VISHNUSOMAN” and see what is in their “OU” column.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [April 19, 2024, 3:38pm UTC](https://forums.powershell.org/t/need-assistance/23977/12 "2024-04-19T15:38:28Z")

</div>

This is not the OP’s code. They copied from: [Create Active Directory Users from CSV with PowerShell - ALI TAJRAN](http://alitajran.com/create-active-directory-users-from-csv-with-powershell), specifically: [alitajran.com/wp-content/uploads/scripts/Add-NewUsers.ps1](https://www.alitajran.com/wp-content/uploads/scripts/Add-NewUsers.ps1)

So basically, OP has googled, copied something from the internet, ran into an error, and is asking for help now here.

The issue is almost certainly with the value being passed to -Path in the `New-ADUser` part of this script. It’s likely a valid object, but not an OU, hence the error. OP needs to provide the proper OU value in the CSV, it’s probably incorrect (like a group or something). This isn’t inherently a PS code issue, as much as just bad data from the CSV probably.

---

<div class="post-metadata">

**Author:** ![grey0ut](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/grey0ut/32/5310_2.png) [@grey0ut](https://forums.powershell.org/u/grey0ut)\
**Post date:** [April 19, 2024, 11:05pm UTC](https://forums.powershell.org/t/need-assistance/23977/13 "2024-04-19T23:05:47Z")

</div>

good eye @dotnVo , I didn’t even check their username and just assumed they were Ali Tajran 🤣  
I think i’m seeing the full picture now.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [April 23, 2024, 3:09am UTC](https://forums.powershell.org/t/need-assistance/23977/14 "2024-04-23T03:09:37Z")

</div>

Closed on April 23, 2024, 3:09am UTC


