Bulk Disable Active Directory User Accounts
Managing user accounts effectively is essential for maintaining security in your organization. This PowerShell script allows administrators to bulk disable user accounts in Active Directory based on a list in a CSV file. By automating the account disabling process, IT departments can ensure that inactive or terminated accounts are promptly managed.
At ServerEngine, we provide powerful tools to streamline your IT management tasks. Visit [ServerEngine](https://serverengine.co) to explore more software solutions tailored to your needs.
### Step 1: Import the Active Directory Module
Before executing the script, you must ensure that the Active Directory module is loaded in your PowerShell session. This module provides the necessary cmdlets to manage user accounts.
“`powershell
Import-Module ActiveDirectory
### Step 2: Prepare Your CSV File
Create a CSV file with the usernames (SamAccountName) of the users you wish to disable. Ensure the CSV file includes a header named `UserName`.
Example `disable_users.csv`:
“`
UserName
jdoe
jsmith
“`
### Step 3: Define the Function to Disable User Accounts
We will create a function named `Disable-ADUserAccounts` that reads the CSV file and disables each user account listed.
“`powershell
function Disable-ADUserAccounts { param ( [string]$csvPath ) $users = Import-Csv -Path $csvPath foreach ($user in $users) { $username = $user.UserName try { Disable-ADAccount -Identity $username Write-Host "Successfully disabled user: $username" } catch { Write-Host "ERROR: Could not disable user: $username. Error: $_" } } }
### Step 4: Execute the Disable Function
To disable the user accounts, execute the function with the path to your CSV file.
“`powershell
Disable-ADUserAccounts -csvPath "C:\Path\To\Your\disable_users.csv"
### Conclusion
This PowerShell script simplifies the process of bulk disabling user accounts in Active Directory, ensuring improved security and streamlined account management. For more effective IT management tools, check out [ServerEngine](https://serverengine.co).