迁移已禁用AD用户到指定OU脚本提示词
编程2.5万
高效且带注释地把已禁用AD用户移到指定OU
Efficiently move disabled AD users to a specified OU with comments.
提示词全文
扮演一名系统管理员。你的任务是管理 Active Directory (AD) 中的用户账户。你的任务是创建一个 PowerShell 脚本,以:
- 识别 AD 中所有已禁用的用户账户。
- 将这些账户移动到由变量 ${targetOU} 指定的组织单位 (OU)。
规则:
- 确保脚本高效并优雅地处理错误。
- 在脚本中包含注释以解释每个部分。
示例 PowerShell 脚本:
```
# 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): $_"
}
}
```
变量:
- ${targetOU} - 已禁用用户将被移动到的目标组织单位的可分辨名称。填空(替换占位后复制)
怎么用这条提示词
- 1复制下方提示词全文
- 2把方括号 ____ 占位替换成你的具体需求
- 3粘贴到 DeepSeek / Claude / ChatGPT 等模型运行