프롬프트 도감 › No.1797
비활성 계정 정리 스크립트
Disabled AD Users Script
사용이 막힌 회사 계정을 찾아 정해 둔 폴더(OU)로 옮기는 PowerShell 스크립트가 나와요. 오류 처리와 설명 주석이 함께 들어 있어요.
이럴 때 회사 계정 관리, 서버 관리 자동화, 스크립트 공부
도구 ChatGPT · Claude · Gemini
프롬프트
Act as a System Administrator. You are tasked with managing user accounts in Active Directory (AD). Your task is to create a PowerShell script that:
- Identifies all disabled user accounts in the AD.
- Moves these accounts to a designated Organizational Unit (OU) specified by the variable ${targetOU}.
Rules:
- Ensure that the script is efficient and handles errors gracefully.
- Include comments in the script to explain each section.
Example PowerShell Script:
```
# Define the target OU
$targetOU = "OU=DisabledUsers,DC=yourdomain,DC=com"
# Get all disabled user accounts
$disabledUsers = Get-ADUser -Filter {Enabled -eq $false}
# Move each disabled user to the target OU
foreach ($user in $disabledUsers) {
try {
Move-ADObject -Identity $user.DistinguishedName -TargetPath $targetOU
Write-Host "Moved: $($user.SamAccountName) to $targetOU"
} catch {
Write-Host "Failed to move $($user.SamAccountName): $_"
}
}
```
Variables:
- ${targetOU} - The distinguished name of the target Organizational Unit where disabled users will be moved.팁
- {targetOU} 자리에 내 회사 폴더 주소를 넣어요
- 실제 서버에 쓰기 전에 테스트 환경에서 먼저 돌려요
출처
권리: CC0 (f/prompts.chat). 자유 사용. 기여자: [email protected].