export all enabled users

In today’s blog post, we’ll explore how to efficiently export information about all enabled users from Active Directory using a PowerShell script. This can be particularly useful for system administrators who need to maintain an up-to-date record of active users within their organization.

Active Directory is a powerful tool for managing users, computers, and other resources in a Windows environment. PowerShell, with its extensive capabilities for scripting and automation, provides a convenient way to interact with Active Directory.

Our goal is to create a PowerShell script that retrieves and exports information about all enabled users in Active Directory to a CSV file.

Script Implementation:
# Import the Active Directory module
Import-Module ActiveDirectory

# Specify the output file path
$outputFilePath = “C:\ad_reports\EnabledUsers.csv”

# Get all enabled users and export to CSV
Get-ADUser -Filter {Enabled -eq $true} -Properties * | Select-Object SamAccountName, DisplayName, GivenName, Surname, UserPrincipalName, Enabled | Export-Csv -Path $outputFilePath -NoTypeInformation

Write-Host “Enabled users exported to $outputFilePath”

This script:

  1. Imports the Active Directory module (make sure the module is available on your system).
  2. Retrieves all enabled users using Get-ADUser with a filter for enabled users.
  3. Selects specific user properties (you can customize the properties based on your requirements).
  4. Exports the selected user information to a CSV file using Export-Csv.

Save the script with a .ps1 extension and execute it in a PowerShell environment. Ensure that you have the necessary permissions to query Active Directory. If the Active Directory module is not available, you may need to install the Remote Server Administration Tools (RSAT) or use a system with the Active Directory module already installed.


Conclusion: This PowerShell script simplifies the process of exporting information about enabled users from Active Directory. System administrators can customize the script further by adjusting the selected properties or incorporating additional filters based on their specific requirements.

By amit_g

Welcome to my IT Infra Blog! My name is Amit Kumar, and I am an IT infrastructure expert with over 11 years of experience in the field. Throughout my career, I have worked with a wide variety of systems and technologies, from network infrastructure and cloud computing to hardware and software development. On this blog, I aim to share my knowledge, insights, and opinions on all things related to IT infrastructure. From industry trends and best practices to tips and tricks for managing complex systems, my goal is to provide valuable information that will help IT professionals and enthusiasts alike. Whether you are a seasoned IT veteran or just getting started in the field, I hope you will find my blog to be a valuable resource. In addition to sharing my own thoughts and ideas, I also welcome feedback, comments, and questions from my readers. I believe that a collaborative approach is the best way to advance the field of IT infrastructure and I look forward to hearing from you. Thank you for visiting my blog, and I hope you will continue to follow along as I explore the fascinating world of IT infrastructure. Sincerely, Amit Kumar

Leave a Reply

Your email address will not be published. Required fields are marked *