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
- Fill in targetOU below (or keep the suggested defaults).
- Copy the generated prompt.
- 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
English Translator and Improver
English Translator and Improver — a ready-to-use text prompt with customizable fields (Your first sentence) for Writing & Content. Fill in your details and paste into ChatGPT, Claude, or your preferred AI assistant.
Storyteller
Storyteller — a ready-to-use text prompt with customizable fields (Your first request) for Writing & Content. Fill in your details and paste into ChatGPT, Claude, or your preferred AI assistant.
Football Commentator
Football Commentator — a ready-to-use text prompt with customizable fields (Your first request) for Writing & Content. Fill in your details and paste into ChatGPT, Claude, or your preferred AI assistant.
Screenwriter
Screenwriter — a ready-to-use text prompt with customizable fields (Your first request) for Writing & Content. Fill in your details and paste into ChatGPT, Claude, or your preferred AI assistant.