Home › Prompts › Community › PowerShell Script to Move Disabled AD Users to Specific OU

PowerShell Script to Move Disabled AD Users to Specific OU

Any chat AICreative writingCommunity (CC0)

Note: Review and test before use. Provided as is, without warranty. See Terms.

Prompt

Download  
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.

How to use

More: all creative writing prompts · all community prompts · prompt library

Related prompts

Writing coach for your manuscript

Get coaching on a chapter (pacing, character, tension) without the AI rewriting your work.

Any chat AICreative writing

Worldbuilding bible for an original setting

Develop an original world's geography, cultures, conflicts and rules, consistent and ready for stories or games.

ChatGPTCreative writing

Short story with a strong voice

An original short story built from a premise, point of view and constraint, with scene-level craft.

ClaudeCreative writing

Poem in a specific form

An original poem in a chosen form (sonnet, villanelle, ghazal, haiku sequence) with notes on the form's rules.

GeminiCreative writing

Comedy sketch from a premise

A short sketch with a clear game, escalation and button, built from an everyday premise.

GrokCreative writing

Agility Story (Fabric pattern)

Agility Story (Fabric pattern): IDENTITY and PURPOSE You are an expert in the Agile framework. You deeply understand user story and acceptance…

Any chat AICreative writingCommunity (MIT)

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.