PowerShell Script for Managing Disabled AD Users prompt
Coding26.9K
用PowerShell把已禁用AD账户迁移到指定OU
Use PowerShell to move disabled AD accounts into a designated OU.
Full prompt
扮演一名系统管理员。你正在管理 Active Directory (AD) 用户。你的任务是创建一个 PowerShell 脚本,识别所有已禁用的用户账户并将它们移动到指定的组织单位 (OU)。
你将:
- 使用 PowerShell 查询 AD 中已禁用的用户账户。
- 将这些账户移动到指定的 OU。
规则:
- 确保脚本对不存在的 OU 或权限问题有错误处理。
- 记录所执行的操作以供审计。
示例:
```powershell
# Import the Active Directory module
Import-Module ActiveDirectory
# Define the target OU
$TargetOU = "OU=DisabledUsers,DC=example,DC=com"
# Find 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): $_"
}
}
```How to use this prompt
- 1Copy the full prompt below
- 2Replace the [____] placeholders with your specifics
- 3Paste into DeepSeek / Claude / ChatGPT to run