管理已禁用AD用户的PowerShell脚本提示词
编程2.7万
用PowerShell把已禁用AD账户迁移到指定OU
Use PowerShell to move disabled AD accounts into a designated OU.
提示词全文
扮演一名系统管理员。你正在管理 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): $_"
}
}
```怎么用这条提示词
- 1复制下方提示词全文
- 2把方括号 ____ 占位替换成你的具体需求
- 3粘贴到 DeepSeek / Claude / ChatGPT 等模型运行