Link to home
Start Free TrialLog in
Avatar of JJ KR
JJ KRFlag for India

asked on

ACtive Directory OUs users Import

Dear Experts,

Thanks in Advance. I found this script on Internet and tried to import Bulk users to AD and it was successful. The issue is when the user tried to login password is not accepting. Its not possible to reset all users password manually. Kindly let me know what to do.

###########################################################
# AUTHOR  : Kelly Bush
# DATE    : 1/16/2014  
# COMMENT : Creates Active Directory users and populates
#           different attributes based on import_users.csv
# Based on: PowerShell: Create Active Directory Users Based On Excel Input
###########################################################
Import-Module ActiveDirectory
$path     = Split-Path -parent $MyInvocation.MyCommand.Definition
$newpath  = $path + "\import_users.csv"
# Define variables
$log      = $path + "\created_ActiveDirectory_users.log"
$date     = Get-Date
$i        = 0

Function createActiveDirectoryUsers
{

"Created the following Active Directory users (on " + $date + "): " | Out-File $log -append
"--------------------------------------------" | Out-File $log -append

  Import-CSV $newpath | ForEach-Object {
    $samAccount = $_.SamAccountName
    Try   { $exists = Get-ADUser -LDAPFilter "(sAMAccountName=$samAccount)" }
    Catch { }
    If(!$exists)
    {
      $i++
      # Set all variables according to the table names in the Excel
      # sheet / import CSV. The names can differ in every project, but
      # if the names change, make sure to change it below as well.
      $setpass = ConvertTo-SecureString -AsPlainText $_.Password -force
      New-ADUser -Name $_.DisplayName -SamAccountName $_.SamAccountName -GivenName $_.GivenName -Initials $_.Initials `
      -Surname $_.SN -DisplayName $_.DisplayName -Office $_.OfficeName `
      -Description $_.Description -EmailAddress $_.eMail `
      -StreetAddress $_.StreetAddress -City $_.L `
      -PostalCode $_.PostalCode -Country $_.CO -UserPrincipalName $_.UPN `
      -Company $_.Company -Department $_.Department -EmployeeID $_.ID `
      -OfficePhone $_.Phone -AccountPassword $setpass -Enabled $true -Path $_.OU  
 
      $output  = $i.ToString() + ") Name: " + $_.CN + "  sAMAccountName: " 
      $output += $sam + "  Pass: " + $_.Password
      $output | Out-File $log -append
    }
    Else
    {
      "SKIPPED - USER ALREADY EXISTS OR ERROR: " + $_.CN | Out-File $log -append
    }
  }
  "----------------------------------------" + "`n" | Out-File $log -append
}
# Run function
createActiveDirectoryUsers
#End Script
ASKER CERTIFIED SOLUTION
Avatar of Naveen Joshi
Naveen Joshi
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Seuno
Seuno

^^ seuno if i am not wrong its DSMOD not DSMOND. Correct me if i am.
Avatar of joensw
Install the (depending on your flavour of your workstation OS) Remote Server Administration Tools so you get the AD DS tools. Don't forget to go into your Windows Features in Control Panel to enable the correct toolsets.

Once you've done that, the following command will achieve your desired result:

DSQUERY user "OU=myOU,OU=myUsers,DC=myDomain,DC=loc" -limit 0 | DSMOD user -pwd <insert new password here>


Replace "OU=myOU,OU=myUsers,DC=myDomain,DC=loc" with the distinguishedName of the OU containing the users to be changed
@ Naveen you are right.