Wednesday, May 16, 2018

 

[ActiveDirectory] Powershell to reset AD user password remotely



Powershell to reset AD user password remotely







[Explanation]

### 접속 계정 및 초기화 대상 경로 지정
$target=New-Object System.Collections.ArrayList 
#[변경필요] 접속 계정은 Account Operator 권한을 갖고 있어야 합니다.
$user='domain\administrator'  
#[변경필요] 초기화시킬 복수의 계정을 list.txt 파일에 sAMAccountName 만 입력합니다. 
$target=Get-Content C:\Users\administrator\Desktop\AD_Reset_Password_MulitAccounts\accounts.txt 


### 스크립트 영역
set-ExecutionPolicy RemoteSigned
$result= Invoke-Command -ComputerName (server info)  -credential $user  -ScriptBlock {param($user, $target) ;import-module activedirectory; $pwd='(reset password)' ;$securepwd = ConvertTo-SecureString $pwd -AsPlainText -Force;  $target | %{Set-ADAccountPassword $_ -NewPassword $securepwd -Reset -PassThru } ; $target  | %{ get-aduser -properties * -filter {sAMAccountName -eq $_ } | select sAMAccountName, PasswordLastSet } }   -ArgumentList $user, $target
$cnt=$target.Length
$num=0
For ( $c=0; $c -lt $cnt ; $c++){
      $result[$c].sAMAccountName+" ----- "+$result[$c].PasswordLastSet
    }
sleep -Seconds 3
Remove-Variable user,cnt,result,target





댓글이나 의견은 언제든지 환영합니다.

Your Comments are Always Welcomed!
Share:

0 comments:

Post a Comment