PoshCode Archive  Artifact [c3cdc97820]

Artifact c3cdc97820c20d4a0ad314304ea86027454d6d240a20baa9d13b4d9feb7c4a75:

  • File Bulk-Change-AD-Passwords.ps1 — part of check-in [802279d299] at 2018-06-10 13:09:32 on branch trunk — Bulk change account passwords without requiring elevated permissions. (user: unknown size: 1278)

# encoding: ascii
# api: powershell
# title: Bulk Change AD Passwords
# description: Bulk change account passwords without requiring elevated permissions.
# version: 0.1
# license: CC0
# x-poshcode-id: 2394
# x-archived: 2010-12-03T12:56:34
#
# Requires an input file in the format : Account, oldpassword, Newpassword
#

#-------------------------------------------------------------
# install http://www.quest.com/powershell/activeroles-server.aspx
 Add-PSSnapin Quest.ActiveRoles.ADManagement

# CSV Format : NTAccountName,oldpassword,newpassword


$UserList = Import-Csv c:\temp\users.csv # | select-object -first 2 

$userlist | foreach-object {
    Write-output -----------------------------------------------
    Write-output $_.NTAccountName

    $ADUser= Get-QADUser  $_.NTAccountName
    $ADSIUser = [adsi] $ADUser.Path
    
    Write-output $ADSIUser.displayName
    Write-output "Changing password from $($_.OldPassword) to $($_.NewPassword) ...."
    $result = $ADSIUser.psbase.invoke("ChangePassword",$_.OldPassword, $_.NewPassword)
    Write-output "Password change result $result"
    ## Error and success handling is needed 0 is OK the rest is an error 
    ## http://msdn.microsoft.com/en-us/library/aa772195(v=VS.85).aspx 
}