Book Image

Active Directory with PowerShell

By : Pamarthi Venkata Sitaram, YELLAPRAGADA U PADMAVATHI
5 (1)
Book Image

Active Directory with PowerShell

5 (1)
By: Pamarthi Venkata Sitaram, YELLAPRAGADA U PADMAVATHI

Overview of this book

Table of Contents (16 chapters)
Active Directory with PowerShell
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Resetting the password for multiple user accounts


Often, Windows administrators get requests to reset the password for a bunch of users. You can do this via a GUI approach if you have the time and patience. Otherwise, use the following function, which is an efficient way to do this. This function prompts for the password that you want to set for the users. This password should match the password complexity policy of your domain. You can pass the list of users to the UserName parameter either as a Comma-Separated Value or by reading from a text file:

Function Reset-ADuserPassword {
[CmdletBinding()]
Param(
    [string[]]$UserName
)
$Password = Read-Host "Enter the password that you want to set for the users" -AsSecureString
foreach($User in $UserName) {
    try {
        Set-ADAccountPassword -Identity $User -Reset -NewPassword  $Password -EA Stop
        Write-Host "Password successfully changed for $user"
    } catch {
        Write-Warning "Failed to reset password for $user. $_"
    }...