InnerVault

PowerShell Script to Move Disabled AD Users to Specific OU

Indexedprompts.chat (CC0 prompt collection), dark.valerik.spb@gmail.com

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…

Open the source (opens github.com) https://github.com/f/prompts.chat

What it is

Prompts from dark.valerik.spb@gmail.com.

The problem it solves and who it suits haven't been reviewed by InnerVault. The description above is the source's own.

The prompt

Fill in before using: ${targetOU}

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.

Written by the prompts.chat (CC0 prompt collection) community (dark.valerik.spb@gmail.com). Not tested by InnerVault.

How to get it

Setup steps: not applicable.

Related

  1. 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…

    Indexed prompts.chat (CC0 prompt collection), dark.valerik.spb@gmail.com CC0-1.0

  2. Suspense full 2D documentary script generator prompt like Anidoc anihis hindi

    Indexed prompts.chat (CC0 prompt collection), rimypop5@gmail.com CC0-1.0

  3. script

    Prompts

    Act as an executive speechwriter. Analyze the attached screenshot/text data and convert it into a highly laconic, professional weekly update presentation script delivered with gravitas. Follow these strict constraints…

    Indexed prompts.chat (CC0 prompt collection), kennynah85@gmail.com CC0-1.0

  4. # Shell Script Specialist You are a senior shell scripting expert and specialist in POSIX-compliant automation, cross-platform compatibility, and Unix philosophy. ## Task-Oriented Execution Model - Treat every…

    Indexed prompts.chat (CC0 prompt collection), wkaandemir CC0-1.0

  5. You are an expert Linux script developer. I want you to create professional Bash scripts that automate the workflows I describe, featuring error handling, colorized output, comprehensive parameter handling with help…

    Indexed prompts.chat (CC0 prompt collection), viardant CC0-1.0

  6. --- name: package-json-scripts-auditor description: Audits the scripts section of an npm package.json for safety and clarity: risky install hooks, curl-pipe-to-shell, rm -rf, sudo, inline secrets, unpinned npx…

    Indexed prompts.chat (CC0 prompt collection), f CC0-1.0