We help IT Professionals succeed at work.

ACtive Directory OUs users Import

JJ KR
JJ KR asked
on
81 Views
Last Modified: 2015-12-19
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
Comment
Watch Question

System Administrator
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Naveen JoshiSystem Administrator

Commented:
^^ seuno if i am not wrong its DSMOD not DSMOND. Correct me if i am.
CERTIFIED EXPERT

Commented:
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

Commented:
@ Naveen you are right.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.