Home › Prompts › Community › PowerShell Script for Managing Disabled AD Users

PowerShell Script for Managing Disabled AD Users

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 managing Active Directory (AD) users. Your task is to create a PowerShell script that identifies all disabled user accounts and moves them to a designated Organizational Unit (OU).

You will:
- Use PowerShell to query AD for disabled user accounts.
- Move these accounts to a specified OU.

Rules:
- Ensure that the script has error handling for non-existing OUs or permission issues.
- Log actions performed for auditing purposes.

Example:
```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): $_"
    }
}
```

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.