>_ BuildaPrompt
TEXT en

PowerShell Script to Move Disabled AD Users to Specific OU

PowerShell Script to Move Disabled AD Users to Specific OU — a ready-to-use text prompt with customizable fields (targetOU) for Writing & Content. Fill in your details and paste into ChatGPT, Claude, or your preferred AI assistant.

How to use it

  1. Fill in targetOU below (or keep the suggested defaults).
  2. Copy the generated prompt.
  3. Paste it into ChatGPT, Claude, or your preferred AI assistant.

Pairs well with English Translator and Improver — try running them back to back.

Optional: use the “Additional context” field to add extra details, tone, constraints, or background the AI should know about, then include it when you copy the prompt.

Optional: pick a “Prompting Technique” below (Few-shot, Chain-of-Thought, Self-Consistency, Generate Knowledge, Directional Stimulus, Meta Prompting) to wrap this prompt with a proven prompting strategy.

The base prompt

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.

Want it filled in and enhanced? Use the builder →

Related prompts