darkvalerikspb

@darkvalerikspbUnclaimed · imported

This profile was created from github.com/darkvalerikspb so the prompts could be credited. Are you darkvalerikspb?

Claim this profileRequest removal

github.com/darkvalerikspbJoined Nov 29, 20260 points0 followers·0 following
darkvalerikspb@darkvalerikspbCoding

Script to move disabled AD users into a chosen OU

Acts as a sysadmin and writes a commented, error-tolerant PowerShell script that finds all disabled Active Directory user accounts and moves them to a target OU set by a variable.

v2
Imported·via prompts.chat·Unclaimed·CC0
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.
darkvalerikspb@darkvalerikspbCoding

Script to find disabled AD users and move them to a holding OU

A system administrator prompt asking for a PowerShell script that queries Active Directory for disabled user accounts, moves them to a designated OU, handles errors for missing OUs or permissions, and logs actions for auditing.

Imported·via prompts.chat·Unclaimed·CC0
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): $_"
    }
}
```