PowerShell Script to Move Disabled AD Users to Specific OU prompt

Coding24.5K

高效且带注释地把已禁用AD用户移到指定OU

Efficiently move disabled AD users to a specified OU with comments.

Full prompt
扮演一名系统管理员。你的任务是管理 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} - 已禁用用户将被移动到的目标组织单位的可分辨名称。
Fill in the blanks, then copy

How to use this prompt

  1. 1Copy the full prompt below
  2. 2Replace the [____] placeholders with your specifics
  3. 3Paste into DeepSeek / Claude / ChatGPT to run

Related Coding prompts