This repository contains PowerShell scripts to export Active Directory (AD) user and computer information. These scripts can handle different use cases, including exporting data from multiple domain controllers (DCs), exporting data from specific organizational units (OUs), and generating combined reports.
Exports user account details from multiple domain controllers into a single CSV file.
-
Features:
- Gathers user details such as
SID
,DisplayName
,LastLogonTimestamp
, and other account properties. - Combines results from multiple domain controllers into a single report.
- Removes temporary files after processing.
- Gathers user details such as
-
Usage:
- Update the domain controller variables
$DC1
and$DC2
in the script. - Specify the export file paths.
- Run the script to generate the report.
- Update the domain controller variables
Exports computer account details from multiple domain controllers into a single CSV file.
-
Features:
- Gathers computer details such as
Name
,DNSHostName
,IPv4Address
, andLastLogonTimestamp
. - Combines results from multiple domain controllers into a single report.
- Cleans up temporary files after completion.
- Gathers computer details such as
-
Usage:
- Update the domain controller variables
$DC1
and$DC2
in the script. - Specify the export file paths.
- Run the script to generate the report.
- Update the domain controller variables
A more advanced script that exports user account details to an Excel workbook, organizing data by OUs and including users outside of the specified OUs.
-
Features:
- Supports multiple domain controllers for redundancy.
- Exports user details for specific OUs into separate Excel worksheets.
- Filters and exports users outside the defined OUs into an "Other" worksheet.
- Uses the
ImportExcel
module for creating Excel files.
-
Usage:
- Install the
ImportExcel
module by running:Install-Module -Name ImportExcel -Scope CurrentUser
- Update the
$DCs
variable with your domain controllers. - Define the desired OUs and their corresponding worksheet names in the
$OUs
variable. - Specify the output Excel file path.
- Run the script to generate the Excel report.
- Install the
-
Active Directory Module:
- Ensure the Active Directory module is installed on the machine running the scripts.
Install-WindowsFeature -Name RSAT-AD-PowerShell
-
ImportExcel Module (for
ADExportWithExcel.ps1
):- Install the
ImportExcel
PowerShell module:Install-Module -Name ImportExcel -Scope CurrentUser
- Install the
-
Required Folders:
- Create the necessary directories:
C:\Scripts
for temporary files.C:\CSVReports
for final output files.
- Create the necessary directories:
- Open PowerShell with administrative privileges.
- Navigate to the directory containing the script.
- Run the desired script:
.\ScriptName.ps1
-
ADUserExport.ps1
andADComputerExport.ps1
:- CSV files containing the exported data, saved in the
C:\CSVReports
folder.
- CSV files containing the exported data, saved in the
-
ADExportWithExcel.ps1
:- An Excel workbook (
ADExport.xlsx
) with multiple worksheets, saved in theC:\CSVReports
folder.
- An Excel workbook (
Feel free to submit issues or pull requests if you encounter any bugs or have ideas for improvement!
This project is licensed under the MIT License. See the LICENSE file for details.