728x90

[환경]

Windows Server 2008 R2

     

     

파워쉘을 이용하여 사용자 계정에 대한 최근 접속 이력을 체크하고 특정 조건을 사용하여 비활성화 하는 방법

     

     

1. Active Directory 모듈 활성

Get-ADUser, Disable-ADAccount, Move-ADObject 명령을 실행하기 위해 도메인 컨트롤러 서버에서 Active Directory Powershell 모듈을 활성화합니다.

Import-Module ActiveDirectory

     

2. 조회

다음 조건을 만족하는 사용자를 조회합니다.

*조건1. 마지막 로그온 날짜가 30일 이상 지남

Get-ADUser -Filter * -Properties "LastLogonDate" | sort-object -property lastlogondate -descending | where-object {$_.LastLogonDate -le ((get-date).AddDays(-30))} | where-object {$_.LastLogonDate -ne $null} | Format-Table -property name, lastlogondate, DistinguishedName, Enabled -AutoSize

   

3. 계정 Disable

다음 조건을 만족하는 사용자는 상태를 disable로 변경합니다.

*조건1. 마지막 로그온 날짜가 30일 이상 지남

Get-ADUser -Filter * -Properties "LastLogonDate" | where-object {$_.LastLogonDate -le ((get-date).AddDays(-30))} | where-object {$_.LastLogonDate -ne $null} | Disable-ADAccount

     

결과> 계정 상태 변경 (disable)

     

4. 계정 OU 이동

다음 조건을 만족하는 사용자를 "Prison" OU로 이동합니다.

*조건1. 마지막 로그온 날짜가 30일 이상 지남

*조건2. Disable 상태

Get-ADUser -Filter * -Properties "LastLogonDate" | where-object {$_.LastLogonDate -le ((get-date).AddDays(-30))}

| where-object {$_.LastLogonDate -ne $null} | where-object {$_.Enabled -eq $false} | Move-ADObject -TargetPath "OU=Pris

on,DC=corp,DC=hypark,DC=lab"

     

결과> Users2 에서 Prison 으로 OU 변경 됨

728x90
728x90

Enable-ADOptionalFeature –Identity "CN=RecycleBin Feature,CN=Optional Features,CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=koreare,DC=com" –Scope ForestOrConfigurationSet –Target "koreare.com"

   

Get-ADObject -SearchBase "CN=Deleted Objects,DC=koreare,DC=com" -ldapFilter "(objectClass=*)" -includeDeletedObjects | Format-List Name,ObjectClass,ObjectGuid

   

Restore-ADObject –identity c6cbe4b3-ed3d-45d6-ab46-fd6223ca7075

   

생성 된 계정 확인

   

끝.

728x90
728x90
Install-windowsfeature -name AD-Domain-Services –IncludeManagementTools


728x90

+ Recent posts