Tuesday, March 21, 2017

Reset Ad user password in OU

Reset Active Directory multiple users password in OU using powershell:

# Specify the OU.
$OU = [ADSI]"LDAP://ou=West,dc=MyDomain,dc=local"

# 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""123-zxc")
        # Expire the password.
        $User.pwdLastSet = 0
        $User.SetInfo()
    }
}

No comments: