JJ KR
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.De finition
$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=$samAccou nt)" }
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
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.De
$newpath = $path + "\import_users.csv"
# Define variables
$log = $path + "\created_ActiveDirectory_
$date = Get-Date
$i = 0
Function createActiveDirectoryUsers
{
"Created the following Active Directory users (on " + $date + "): " | Out-File $log -append
"-------------------------
Import-CSV $newpath | ForEach-Object {
$samAccount = $_.SamAccountName
Try { $exists = Get-ADUser -LDAPFilter "(sAMAccountName=$samAccou
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
}
}
"-------------------------
}
# Run function
createActiveDirectoryUsers
#End Script
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
^^ seuno if i am not wrong its DSMOD not DSMOND. Correct me if i am.
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=myD omain,DC=l oc" -limit 0 | DSMOD user -pwd <insert new password here>
Replace "OU=myOU,OU=myUsers,DC=myD omain,DC=l oc" with the distinguishedName of the OU containing the users to be changed
Once you've done that, the following command will achieve your desired result:
DSQUERY user "OU=myOU,OU=myUsers,DC=myD
Replace "OU=myOU,OU=myUsers,DC=myD
@ Naveen you are right.
http://serverfault.com/questions/207115/how-do-i-bulk-reset-passwords-for-all-users-in-an-ou