Hi,
We have a business requirement where we have to import all user data from csv file (exported from open Ldap server) into the AD with same attributes/fields so that so that our backend intranet sites/services should not be disturbed.
We want to add users with following attributes to match the current backend sites and services:

We are using following powershell script:
Import-Module ActiveDirectory
$users = Import-Csv -Path "C:\Share\users2.csv"
foreach ($user in $users) {
$SamAccountName = $User.SamAccountName
$Path = $User.path
$Groups = $User.groups
$UserPrincipalName = $user.UserPrincipalName
$cn = $user.cn
$gidNumber = $user.gidNumber
$GivenName = $User.GivenName
$sn = $User.sn
$DisplayName = $User.DisplayName
$uid = $user.uid
$homeDirectory = $User.homeDirectory
$physicalDeliveryOfficeName = $User.physicalDeliveryOfficeName
$o = $User.o
$l = $User.l
$EmailAddress = $User.email
$uidNumber = $User.uidNumber
$postalAddress = $User.postalAddress
$st = $User.st
$homePostalAddress = $User.homePostalAddress
$employeeNumber = $User.employeeNumber
$Title = $User.title
$telephoneNumber = $User.telephoneNumber
$mobile = $User.mobile
$homePhone = $User.homePhone
$manager = $User.manager
$homeDrive = $User.homeDrive
$profilePath = $User.profilePath
$secretary = $User.secretary
$AccountPassword = (ConvertTo-SecureString $User.password -AsPlainText -Force)
$Enabled = $true
$ChangePasswordAtLogon = $true
New-ADUser -SamAccountName $samAccountName -GivenName $givenName -Surname $surname -UserPrincipalName $userPrincipalName -OtherAttributes @{gidNumber = $gidNumber; secretary = $secretary}
}
but it is giving us following errors:
PS C:\share\Import Users> .\users2.ps1
New-ADUser : Identity info provided in the extended attribute: 'Manager' could not be resolved. Reason: 'Cannot find an object with identity: '' under: 'DC=genetech,DC=pk'.'.
At C:\share\Import Users\users2.ps1:40 char:5
+ New-ADUser -SamAccountName $SamAccountName -Name $Name -UserPrinc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (CN=Mustafa Hema...=genetech,DC=pk:String) [New-ADUser], ADIdentityResolutionException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityResolutionException,Microsoft.ActiveDirectory.Management.Commands.NewADUser
Set-ADUser : The parameter is incorrect
At C:\share\Import Users\users2.ps1:44 char:5
+ Set-ADUser -Identity $SamAccountName -Add @{ ou = '$ou'; cn = '$c ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (mustafa.hemani:ADUser) [Set-ADUser], ADInvalidOperationException
+ FullyQualifiedErrorId : ActiveDirectoryServer:87,Microsoft.ActiveDirectory.Management.Commands.SetADUser
New-ADUser : Identity info provided in the extended attribute: 'Manager' could not be resolved. Reason: 'Cannot find an object with identity: '' under: 'DC=genetech,DC=pk'.'.
At C:\share\Import Users\users2.ps1:40 char:5
+ New-ADUser -SamAccountName $SamAccountName -Name $Name -UserPrinc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (CN=Shamim Rajan...=genetech,DC=pk:String) [New-ADUser], ADIdentityResolutionException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityResolutionException,Microsoft.ActiveDirectory.Management.Commands.NewADUser
Set-ADUser : The parameter is incorrect
At C:\share\Import Users\users2.ps1:44 char:5
+ Set-ADUser -Identity $SamAccountName -Add @{ ou = '$ou'; cn = '$c ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (shamim.rajani:ADUser) [Set-ADUser], ADInvalidOperationException
+ FullyQualifiedErrorId : ActiveDirectoryServer:87,Microsoft.ActiveDirectory.Management.Commands.SetADUser
New-ADUser : Identity info provided in the extended attribute: 'Manager' could not be resolved. Reason: 'Cannot find an object with identity: '' under: 'DC=genetech,DC=pk'.'.
At C:\share\Import Users\users2.ps1:40 char:5
+ New-ADUser -SamAccountName $SamAccountName -Name $Name -UserPrinc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (CN=Turab Hemani...=genetech,DC=pk:String) [New-ADUser], ADIdentityResolutionException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityResolutionException,Microsoft.ActiveDirectory.Management.Commands.NewADUser
Set-ADUser : Cannot find an object with identity: 'turab.hemani' under: 'DC=genetech,DC=pk'.
At C:\share\Import Users\users2.ps1:44 char:5
+ Set-ADUser -Identity $SamAccountName -Add @{ ou = '$ou'; cn = '$c ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (turab.hemani:ADUser) [Set-ADUser], ADIdentityNotFoundException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,Microsoft.ActiveDirectory.Management.Commands.SetADUser
New-ADUser : The operation failed because UPN value provided for addition/modification is not unique forest-wide
At C:\share\Import Users\users2.ps1:40 char:5
+ New-ADUser -SamAccountName $SamAccountName -Name $Name -UserPrinc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (CN=Urooj Fatima...=genetech,DC=pk:String) [New-ADUser], ADException
+ FullyQualifiedErrorId : ActiveDirectoryServer:8648,Microsoft.ActiveDirectory.Management.Commands.NewADUser
Set-ADUser : Cannot find an object with identity: 'urooj.fatima' under: 'DC=genetech,DC=pk'.
At C:\share\Import Users\users2.ps1:44 char:5
+ Set-ADUser -Identity $SamAccountName -Add @{ ou = '$ou'; cn = '$c ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (urooj.fatima:ADUser) [Set-ADUser], ADIdentityNotFoundException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,Microsoft.ActiveDirectory.Management.Commands.SetADUser
New-ADUser : The operation failed because UPN value provided for addition/modification is not unique forest-wide
At C:\share\Import Users\users2.ps1:40 char:5
+ New-ADUser -SamAccountName $SamAccountName -Name $Name -UserPrinc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (CN=Taqi Kirmani...=genetech,DC=pk:String) [New-ADUser], ADException
+ FullyQualifiedErrorId : ActiveDirectoryServer:8648,Microsoft.ActiveDirectory.Management.Commands.NewADUser
Set-ADUser : Cannot find an object with identity: 'taqi.kirmani' under: 'DC=genetech,DC=pk'.
At C:\share\Import Users\users2.ps1:44 char:5
+ Set-ADUser -Identity $SamAccountName -Add @{ ou = '$ou'; cn = '$c ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (taqi.kirmani:ADUser) [Set-ADUser], ADIdentityNotFoundException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,Microsoft.ActiveDirectory.Management.Commands.SetADUser
New-ADUser : The operation failed because UPN value provided for addition/modification is not unique forest-wide
At C:\share\Import Users\users2.ps1:40 char:5
+ New-ADUser -SamAccountName $SamAccountName -Name $Name -UserPrinc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (CN=Samana Hassa...=genetech,DC=pk:String) [New-ADUser], ADException
+ FullyQualifiedErrorId : ActiveDirectoryServer:8648,Microsoft.ActiveDirectory.Management.Commands.NewADUser
Set-ADUser : Cannot find an object with identity: 'samana.hassan' under: 'DC=genetech,DC=pk'.
At C:\share\Import Users\users2.ps1:44 char:5
+ Set-ADUser -Identity $SamAccountName -Add @{ ou = '$ou'; cn = '$c ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (samana.hassan:ADUser) [Set-ADUser], ADIdentityNotFoundException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,Microsoft.ActiveDirectory.Management.Commands.SetADUser
New-ADUser : The operation failed because UPN value provided for addition/modification is not unique forest-wide
At C:\share\Import Users\users2.ps1:40 char:5
+ New-ADUser -SamAccountName $SamAccountName -Name $Name -UserPrinc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (CN=Aadil Pirani...=genetech,DC=pk:String) [New-ADUser], ADException
+ FullyQualifiedErrorId : ActiveDirectoryServer:8648,Microsoft.ActiveDirectory.Management.Commands.NewADUser
Set-ADUser : Cannot find an object with identity: 'adil.pirani' under: 'DC=genetech,DC=pk'.
At C:\share\Import Users\users2.ps1:44 char:5
+ Set-ADUser -Identity $SamAccountName -Add @{ ou = '$ou'; cn = '$c ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (adil.pirani:ADUser) [Set-ADUser], ADIdentityNotFoundException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,Microsoft.ActiveDirectory.Management.Commands.SetADUser
New-ADUser : The operation failed because UPN value provided for addition/modification is not unique forest-wide
At C:\share\Import Users\users2.ps1:40 char:5
+ New-ADUser -SamAccountName $SamAccountName -Name $Name -UserPrinc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (CN=Shabbir Bhoj...=genetech,DC=pk:String) [New-ADUser], ADException
+ FullyQualifiedErrorId : ActiveDirectoryServer:8648,Microsoft.ActiveDirectory.Management.Commands.NewADUser
Set-ADUser : Cannot find an object with identity: 'shabbir.bhojani' under: 'DC=genetech,DC=pk'.
At C:\share\Import Users\users2.ps1:44 char:5
+ Set-ADUser -Identity $SamAccountName -Add @{ ou = '$ou'; cn = '$c ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (shabbir.bhojani:ADUser) [Set-ADUser], ADIdentityNotFoundException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,Microsoft.ActiveDirectory.Management.Commands.SetADUser
New-ADUser : The operation failed because UPN value provided for addition/modification is not unique forest-wide
At C:\share\Import Users\users2.ps1:40 char:5
+ New-ADUser -SamAccountName $SamAccountName -Name $Name -UserPrinc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (CN=Neelam Rahee...=genetech,DC=pk:String) [New-ADUser], ADException
+ FullyQualifiedErrorId : ActiveDirectoryServer:8648,Microsoft.ActiveDirectory.Management.Commands.NewADUser
Set-ADUser : Cannot find an object with identity: 'neelam.raheel' under: 'DC=genetech,DC=pk'.
At C:\share\Import Users\users2.ps1:44 char:5
+ Set-ADUser -Identity $SamAccountName -Add @{ ou = '$ou'; cn = '$c ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (neelam.raheel:ADUser) [Set-ADUser], ADIdentityNotFoundException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,Microsoft.ActiveDirectory.Management.Commands.SetADUser
New-ADUser : Identity info provided in the extended attribute: 'Manager' could not be resolved. Reason: 'Cannot find an object with identity: '' under: 'DC=genetech,DC=pk'.'.
At C:\share\Import Users\users2.ps1:40 char:5
+ New-ADUser -SamAccountName $SamAccountName -Name $Name -UserPrinc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (CN=Mehreen Huss...=genetech,DC=pk:String) [New-ADUser], ADIdentityResolutionException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityResolutionException,Microsoft.ActiveDirectory.Management.Commands.NewADUser
Set-ADUser : Cannot find an object with identity: 'mehreen.hussain' under: 'DC=genetech,DC=pk'.
At C:\share\Import Users\users2.ps1:44 char:5
+ Set-ADUser -Identity $SamAccountName -Add @{ ou = '$ou'; cn = '$c ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (mehreen.hussain:ADUser) [Set-ADUser], ADIdentityNotFoundException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,Microsoft.ActiveDirectory.Management.Commands.SetADUser
New-ADUser : The operation failed because UPN value provided for addition/modification is not unique forest-wide
At C:\share\Import Users\users2.ps1:40 char:5
+ New-ADUser -SamAccountName $SamAccountName -Name $Name -UserPrinc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (CN=Mehreen Huss...=genetech,DC=pk:String) [New-ADUser], ADException
+ FullyQualifiedErrorId : ActiveDirectoryServer:8648,Microsoft.ActiveDirectory.Management.Commands.NewADUser
Set-ADUser : Cannot find an object with identity: 'mehreen' under: 'DC=genetech,DC=pk'.
At C:\share\Import Users\users2.ps1:44 char:5
+ Set-ADUser -Identity $SamAccountName -Add @{ ou = '$ou'; cn = '$c ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (mehreen:ADUser) [Set-ADUser], ADIdentityNotFoundException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,Microsoft.ActiveDirectory.Management.Commands.SetADUser
Can anyone please help us with perfect scripts which can import the data from CSV file to the correct attributes.
Much Appreciated.