?
Solved

Bulk Password password reset

Posted on 2014-12-28
6
Medium Priority
?
139 Views
Last Modified: 2015-03-16
I need to reset password for all users except 1 user within Active directory.
All users are in same OU (organizational unit).

What is a easiest way to do it?

Environment is windows server 2008 and exchange 2010
0
Comment
Question by:itadminhelp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 7

Expert Comment

by:Deadman
ID: 40521350
The following PowerShell V1 script will reset the password for all users in a specified OU, and also expire the password so it must be changed at next logon:
 
# Specify the OU.
$OU = [ADSI]"LDAP://ou=West,dc=MyDomain,dc=com"

# Enumerate all objects in the OU.
$arrChildren = $OU.Get_Children()
ForEach ($User In $arrChildren)
{
    # Only consider user objects.
    If ($User.Class -eq "user")
    {
        # Set password.
        $User.Invoke("SetPassword", "pAs$w0rd")
        # Expire the password.
        $User.pwdLastSet = 0
        $User.SetInfo()
    }
}

Source:- https://social.technet.microsoft.com/Forums/windowsserver/en-US/b0c2e59f-522e-40a3-ab12-3a95d045d6a8/how-can-reset-password-of-bulk-users-in-one-time-through-ad-or-script?forum=winserverpowershell
0
 
LVL 7

Expert Comment

by:Deadman
ID: 40521354
Or use the following command in command line 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
0
 
LVL 12

Expert Comment

by:Vaseem Mohammed
ID: 40521366
I use this powershell code, for excluding few users.

$NewPassword = Read-Host -asSecureString "New Password"
$UserList = Get-ADUser -Filter * -SearchBase 'OU=OUName,DC=Domain,DC=com' | Where{$_.SAMAccountName -notlike '*username*'}
Foreach($User in $UserList){
 Set-ADAccountPassword -Identity $User.SAMAccountName -NewPassword $NewPassword
}

Open in new window

0
Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

 

Author Comment

by:itadminhelp
ID: 40522981
Thanks guys,

I am really new to PowerShell and scripting. So, bit confused to follow this instruction.

When i look at my AD I see as follows.

Domain: abc.efg.local (For example)

Then I have OU called “Customers” then “Users” underneath that.

All users are in “Users”  OU. I do not want to reset password for just 1 user within that OU. Name of that user is “John” , say username is “john_user”.

I have opened up windows PowerShell on my windows 2008  server.

What do I do now?
How do I run script?
Do i have to type it line by line?
0
 
LVL 7

Expert Comment

by:Deadman
ID: 40523160
0
 
LVL 12

Accepted Solution

by:
Vaseem Mohammed earned 2000 total points
ID: 40523165
$NewPassword = Read-Host -asSecureString "New Password"
$UserList = Get-ADUser -Filter * -SearchBase 'OU=Users,OU=customers,DC=Abc,DC=efg,DC=Local' | Where{$_.SAMAccountName -notlike '*John_user*'}
Foreach($User in $UserList){
 Set-ADAccountPassword -Identity $User.SAMAccountName -NewPassword $NewPassword
}
This should work.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On a regular basis I get questions about slow RDP performance, RDP connection problems, strange errors and even BSOD, remote computers freezing or restarting after initiation of a remote session. In a lot of this cases the quick solutions made b…
Welcome to my series of short tips on migrations. Whilst based on Microsoft migrations the same principles can be applied to any type of migration. My first tip is around source server preparation. No migration is an easy migration, there is a…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question