PowerShell Script for Managing Disabled AD Users
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…
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
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): $_"
}
}
```
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
-
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…
-
2D documentary script generator
PromptsSuspense full 2D documentary script generator prompt like Anidoc anihis hindi
-
script
PromptsAct 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…
-
Shell Script Agent Role
Prompts# 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…
-
Linux Script Developer
PromptsYou 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…
-
package.json Scripts Auditor
Prompts--- 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…