Powershell script for managing disabled ad users pc 0539

PowerShell Script for Managing Disabled AD Users

Scroll down to copy the prompt

Text Updated 1 min read by prompts.chat · @dark.valerik.spb@gmail.com
Advertisement

The prompt

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

Open in

The prompt is copied to your clipboard — just paste it in.

Tags

Advertisement

More like this

Related prompts

English Translator and Improver

Copy this English Translator and Improver AI prompt to get a focused writing response from ChatGPT, Gemini, Claude, or another AI assistant.

Travel Guide

Copy this Travel Guide AI prompt to get a focused writing response from ChatGPT, Gemini, Claude, or another AI assistant.

Screenwriter

Copy this Screenwriter AI prompt to get a focused writing response from ChatGPT, Gemini, Claude, or another AI assistant.