PowerShell script to Disable User Accounts via EMPID
- Avijit Dutta
- 8 hours ago
- 2 min read

🌟 Introduction - PowerShell script to Disable User Accounts via EMPID
In enterprise environments, managing user accounts is a critical responsibility for IT administrators. Automating these tasks with PowerShell not only saves time but also reduces human errors.
In this article, we’ll create a PowerShell script to Disable User Accounts via EMPID:
Fetches Employee IDs (EMPID) from a text file.
Searches for matching users in the domain using sAMAccountName.
Retrieves important user details such as First Name, Given Name, sAMAccountName, and Email.
Disables accounts if found.
Logs results in an Excel file with statuses like "Account Found, Account Disabled" or "Account Not Found".
Finally, email the Excel report 📧 to stakeholders.
⚙️ Prerequisites
Before running the script, ensure the following:
Active Directory Module installed (RSAT-AD-PowerShell).
Proper Domain permissions to query & disable accounts.
C:\Script_AD\Empids.txt file containing EMPIDs (one per line).
Outlook/SMTP configured to send emails.
PowerShell version 5.1 or later.
📝 Steps in the Script
Import EMPIDs from Empids.txt.
Loop through each EMPID and search the domain.
Fetch user details if found.
Disable the account and log status.
Export results to Excel.
Send the report via email to predefined recipients.
💻 Complete PowerShell Script
📥 Download the Script
The full script named "Disable_AD_Users.ps1" is included in the zip file "Disable_AD_Users.zip". You can download it, unzip it, and use it.
📊 Real-World Example
👉 Suppose your company is offboarding employees, and HR provides a list of Employee IDs. Instead of manually searching and disabling accounts, this script automates the entire process in minutes.
✅ Saves time
✅ Reduces manual errors
✅ Provides a professional audit trail in Excel
✅ Ensures security by disabling unused accounts promptly
🎯 Conclusion
With this PowerShell automation, IT admins can handle bulk user account management more efficiently. From fetching employee details to disabling inactive users and generating a professional Excel report, this script streamlines the process end-to-end.
Automation is the key to efficient IT operations – and PowerShell makes it possible! 🚀
📌 SEO Meta Description
☕ Found this helpful? Share it & show some love!
Tip me a coffee at 👉 paypal.me/duttaavijit #ThankYou #SupportCreators
Your small support helps fuel more free, volunteer-driven content like this. Thank you! 🙏
#PowerShell, #ActiveDirectory, #SysAdmin, #Automation, #WindowsServer, #Scripting, #CloudSecurity, #ITOperations, #CyberSecurity, #InfoSec, #Microsoft, #TechTools, #ITAdmin, #AutomationTools, #PowerShellScripts, #SystemAdministration, #TechAutomation, #ServerManagement, #ITSecurity, #WorkplaceAutomation #virtualgyanis
Comments