Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

I always get error when creating users with a script.

$
0
0

Hello,

this is the script that I use :

Import-Module ActiveDirectory 

$Users = Import-Csv -Delimiter ";" -Path "C:\Users\pdj\Documents\ADImportList.csv"  

foreach ($User in $Users)  

{   

    $OU = "OU=users_ou,OU=leraars_ou,DC=edukaronse,DC=be"

    $P = $User.Password 

    $CN= $User.CommonName

    $DN = $User.DisplayName

    $FN = $User.Firstname

    $LN = $User.LastName 

    $UPN = $User.UserPrincipalName

    $SAM = $User.SAM 

    New-ADUser -Name $CN -SamAccountName $SAM -UserPrincipalName $UPN -DisplayName $DN -GivenName $FN -Surname LN -AccountPassword (ConvertTo-SecureString $P -AsPlainText -Force) -Enabled $true -Path $OU -CannotChangePassword $true -PasswordNeverExpires $true

This error is displayed
New-ADUser : Mapobject is niet gevonden
At line:11 char:5
+     New-ADUser -Name $CN -SamAccountName $SAM -UserPrincipalName $UPN -DisplayNa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (CN=Aelvoet Patr...dukaronse,DC=be:String) [New-ADUser], ADIdentityNotFo
   undException
    + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,M
   icrosoft.ActiveDirectory.Management.Commands.NewADUser
New-ADUser : Mapobject is niet gevonden
At line:11 char:5
+     New-ADUser -Name $CN -SamAccountName $SAM -UserPrincipalName $UPN -DisplayNa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (CN=Ahmed Abdel,...dukaronse,DC=be:String) [New-ADUser], ADIdentityNotFo
   undException
    + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,M
   icrosoft.ActiveDirectory.Management.Commands.NewADUser
This is the format of my csv file
SAMPasswordDisplayNameLastNameFirstnameCommonName

UserPrincipalName

Who can help me ?

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles