AD 계정의 암호 만료 일자 Export Powershell script

powershell

AD 시스템을 구축하고 각종 GPO를 deploy하는 과정에서 사용자들에게 직접적으로 불편함을 느끼는 부분이 계정 GPO 관련 부분 입니다. 각종 계정을 제약하는 GPO 항목들 중 특히 계정의 암호를 주기적으로 변경 해야 하는 불편함이 가장 크지 않을까 합니다. 

최근에 각종 보안사고로 인하여, 대기업 위주로 개인 계정의 암호 변경 주기를 3개월 정도로 설정하고, AD의 GPO 또는 계정 관리 전문 프로그램에서 해당 일자만큼만 암호를 사용할 수 있도록 제약하거나, 계정 암호 변경 일자를 추적하여, 특정 일자 이상 사용할 경우 계정이 잠기도록 처리하고 있습니다.

Export 받은 데이터가 조금 정형화 되지 않은 문제만 빼고 전체 계정에 대해서 계정 만료 일자를 정확하게 추출하고 있습니다. 

Powershell commend를 열고, 아래 스크립트를 그대로 입력해도 됩니다.

function Get-XADUserPasswordExpirationDate() {

    Param ([Parameter(Mandatory=$true,  Position=0,  ValueFromPipeline=$true, HelpMessage=”Identity of the Account”)]

    [Object] $accountIdentity)

    PROCESS {

        $accountObj = Get-ADUser $accountIdentity -properties PasswordExpired, PasswordNeverExpires, PasswordLastSet

        if ($accountObj.PasswordExpired) {

            echo (“Password of account: ” + $accountObj.Name + ” already expired!”)

        } else {

            if ($accountObj.PasswordNeverExpires) {

                echo (“Password of account: ” + $accountObj.Name + ” is set to never expires!”)

            } else {

                $passwordSetDate = $accountObj.PasswordLastSet

                if ($passwordSetDate -eq $null) {

                    echo (“Password of account: ” + $accountObj.Name + ” has never been set!”)

                }  else {

                    $maxPasswordAgeTimeSpan = $null

                    $dfl = (get-addomain).DomainMode

                    if ($dfl -ge 3) {

                        ## Greater than Windows2008 domain functional level

                        $accountFGPP = Get-ADUserResultantPasswordPolicy $accountObj

                        if ($accountFGPP -ne $null) {

                            $maxPasswordAgeTimeSpan = $accountFGPP.MaxPasswordAge

                        } else {

                            $maxPasswordAgeTimeSpan = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge

                        }

                    } else {

                        $maxPasswordAgeTimeSpan = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge

                    }

                    if ($maxPasswordAgeTimeSpan -eq $null -or $maxPasswordAgeTimeSpan.TotalMilliseconds -eq 0) {

                        echo (“MaxPasswordAge is not set for the domain or is set to zero!”)

                    } else {

                        echo (“Password of account: ” + $accountObj.Name + ” expires on: ” + ($passwordSetDate + $maxPasswordAgeTimeSpan))

                    }

                }

            }

        }

    }

}

사용 방법

Import-module activedirectory

get-aduser -filter {Enabled -eq $True} -properties * | Get-XADUserPasswordExpirationDate

Share

2 Responses

  1. 안녕하세요? 저희도 AD를 사용중인데요..

    생성한 스크립트는 이름만 추출이되는데

    혹시 계정(xxx@도메인명) 도같이 추출할려면 어떻게 하면될까요..

    어느부분을 수정하면될런지..

    메일로 부탁드려도될까요.>? (jjyyuu@hanmail.net) 입니다.

    • 원본 소스 중 “$accountObj.Name” 항목을 “$accountObj.UserPrincipalName” 으로 변경 하시고, Module reload 하시고 실행하시면 아래와 같이 나옵니다.

      Password of account: “jeongsoo.ha@xxxxx.com” expires on: 04/15/2018 08:11:04
      Password of account: “Jaehyung.Park@xxxxx.com” expires on: 04/11/2018 10:09:28
      Password of account: “junyoung.kim@xxxxx.com” expires on: 03/11/2018 11:21:49
      Password of account: “jiyong.park@xxxxx.com” expires on: 04/02/2018 10:13:56
      Password of account: “jaehwan.kim@xxxxx.com” expires on: 04/24/2018 14:58:24
      Password of account: “jewoo.jeong@xxxxx.com” expires on: 04/08/2018 10:42:03

      감사합니다.

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

Post comment